Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

360

The first thing is to know that there are spacing parameters and spacing commands; \parskip and \parindent belong to the former category, \enskip, \quad and \smallskip to the latter. A complete list of the spacing parameters would be quite long, so let's concentrate on spacing commands. Vertical spacing commands \smallskip, \medskip and \bigskip leave a ...


257

\hsize is the main parameter that TeX uses when typesetting: whenever it finishes a paragraph it looks at the current value of \hsize for breaking it into horizontal boxes. Next, there are \leftskip and \rightskip and possibly other paragraph shape parameters (\hangindent and \hangafter or the more general \parshape). LaTeX uses an indirect approach and ...


132

Use the calc package (\usepackage{calc}): \parbox{\widthof{my text}}{...}


127

I think the simplest way to describe the difference is as follows: \hsize is a TeX primitive that should not be usually used in LaTeX \textwidth is the (constant) width of the total text block \columnwidth is the (constant) width of a single column of text (which is the same as \textwidth for a single column document) \linewidth is a variable that ...


116

I like to answer the question in a more general way, so that it is useful to a wider group of people. There are the following macros which allow to store the width, height (the material above the baseline) and depth (the material below the baseline) of a given content. \settowidth{\somelength}{<content>} \settodepth{\somelength}{<content>} \...


77

This can be done without the calc package \documentclass{article} \begin{document} \newlength{\myl} \settowidth{\myl}{test text} \the\myl \end{document} \the\myl will print out the value ~37pt.


75

Using your code snippet as an example, \centering only has an impact on the \caption. However, \hspace*{\fill} {ILLUSTRATION 1} \hfill {ILLUSTRATION 2} \hspace*{\fill} is meant to set ILLUSTRATION 1 and ILLUSTRATION 2 even distributed across \textwidth: \documentclass{article} \usepackage{showframe}% http://ctan.org/pkg/showframe \begin{document} \begin{...


44

You need layouts package. \documentclass{article} \usepackage{layouts} \begin{document} \drawlist \begin{enumerate} \item foo \currentlist \begin{figure} \listdesign \end{figure} \end{enumerate} \end{document}


40

\newlength is a LaTeX macro which defines a new length register, which holds a length as number and can be used for calculations (e.g. using \addtolength). The \def macro is the primitive version of \(re)newcommand and simply defines the content as string. In your case you want to place the length as string inside the \special which is written into the DVI ...


36

\parskip is the name of the length parameter that contains the current value of the parskip; so \let\currentparskip=\parskip and \setlength{\parskip}{\currentparskip} is equivalent to \setlength{\parskip}{\parskip} and inside a minipage does nothing, as the value of \parskip is already zero. \newlength{\currentparskip} \newenvironment{minipageparskip} {\...


36

TeX has an internal integer register called \mag whose value is initialized to 1000 and can be changed before a page is shipped out. If one sets \mag=1200 all dimensions will be increased by 20%. More precisely they are multiplied by \mag and divided by 1000, unless they are specified with the keyword true before the unit. Thus setting \dimen0=5 true cm ...


32

\newlength is the LaTeX2e version of \newskip. It has extra check to avoid redefinition or illegal name. In LaTeX2e, it is defined \def\newlength#1{\@ifdefinable#1{\newskip#1}} For example, \newlength\foo % OK \newlength\foo % redefinition ERROR! \newlength\endbar % ERROR: \endbar is illegal command name in LaTeX2e. % It is reserved by LaTeX kernel to ...


31

Review the following link: Typesetting Math in LaTeX When we look at spaces in math mode, all spaces are ignored. Thus, $x y$ is the same thing as $xy$. This is very important when typesetting your math formulas, etc. Ways in which you can add spaces include: \, used as $x\, y$ which yields a thinspace \; used as $x\; y$ which yields a thickspace \(space) ...


30

If all you want is to limit the width of your image to some maximum value (like \linewidth), you could simply use the approach described in the TeX FAQ: \documentclass[a5paper]{article} \usepackage{graphicx} \makeatletter \def\maxwidth{% \ifdim\Gin@nat@width>\linewidth \linewidth \else \Gin@nat@width \fi } \makeatother \begin{document} \...


29

TeX has a magnification feature (which is used in plain Tex mostly as the format only loads 10pt fonts by default) it is not really supported or used in LaTeX. If you apply magnification then most lengths are scaled by the appropriate amount, however for referring to physical lengths such as the page size you need to refer to unmagnified lengths, so you can ...


27

You can always query PGF directly: \documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \foreach \width [count=\yi] in {ultra thin,very thin,thin,semithick, thick, very thick, ultra thick} \node[\width] at (0,-0.5*\yi) {The value with the \texttt{\width} option is \the\pgflinewidth}; \end{tikzpicture} \end{document} In a ...


26

The information about 1ex is stored in the font; it is usually the height of a lowercase ‘x’, but it need not be necessarily. You can access the height of an uppercase ‘X’ by \fontcharht\font`X A way for expressing lengths in this ‘unit of measure’ is \newcommand{\eX}{\dimexpr\fontcharht\font`X\relax} so you can say something like \vspace{1.2\eX} or \...


25

The PDF imaging model is quite complicated. You can read about it in section 10.6 of the PDF specification (you can download it here). The important point is that a pixel is supposed to be coloured when painting a shape if any part of it intersects the shape, no matter how small the intersecting area. The idea is to ensure that no shape never disappears ...


22

Just say, in your preamble, \newlength{\savedparindent} and, when you want to change the \parindent, say \setlength{\savedparindent}{\parindent} \setlength{\parindent}{<dimen>} Then you can restore the previous \parindent by \setlength{\parindent}{\savedparindent} This is even unnecessary if you use the environment structure: \newenvironment{...


22

Update The issue with scaling in graphicx is fixed in the development sources for the next release (probably January 2017) and the issue with the xetex driver discussed in the comments is fixed and already on CTAN. The main issue is that the division macro in graphics was written to do a reasonable job for normal image scaling ranges without using more than ...


20

\mywidth is a length register, not a value. In some places it can be used as if it were a value, but if e.g. you would use simply \mywidth in the middle of your text you would get an error. You get the value of a length register with \the. So try \setpagesize{\the\mywidth}{\the\myheight}


20

Both \parbox and \begin{minipage} temporarily reset \parindent=0pt and \parskip=0pt (and a few other parameters), which can be a nuisance. Fortunately, \begin{minipage} also executes the \@minipagerestore macro after this, which is a hook to allow a LaTeX style to override these defaults. (See the ltboxes section in "texdoc source2e".) So just try ...


20

The code can be adapted very easily to not get the warning anymore: \documentclass{minimal} \usepackage{tikz} \begin{document} \noindent \begin{tikzpicture} \draw[line cap=rect] (0,0) -- (\linewidth-\pgflinewidth,0); \end{tikzpicture} \end{document} EDIT: I think I also have an explanation: Each time tikz draws a line, it uses 2 ...


20

If you mean the standard line width, it's 0.4 pt or the setting thin. \tikzstyle{ultra thin}= [line width=0.1pt] \tikzstyle{very thin}= [line width=0.2pt] \tikzstyle{thin}= [line width=0.4pt] \tikzstyle{semithick}= [line width=0.6pt] \tikzstyle{thick}= [line width=0.8pt] \...


20

What you have is the right answer: \documentclass[10pt,a4paper]{article} \newlength{\mytextsize} %This part fails.... (no it doesn't:-) \makeatletter \show\f@size \setlength{\mytextsize}{\f@size pt} \makeatother \showthe\mytextsize \begin{document} %do something. \end{document} which produces a log of: > \f@size=macro: -&...


20

Rubber (elastic) lengths work for \hspace or \vspace, but not when setting a length needed by commands such as \rule, \parbox, \makebox or the minipage environment. The \fill command is equivalent to 0pt plus 1fill, so when a rigid length is needed TeX coerces it to a dimension, in this case 0pt. To the contrary, \parskip accepts a rubber length as its ...


20

It's not really that TeX floating point calculations are inaccurate, it simply isn't doing floating point at all, so you either need a macro implementation such as the xfp package in Werner's answer, or suitably scale the calculation so that it is accurate in the range of fixed point arithmetic being used by TeX and using integer quantities that can be ...


19

You can remove the pt unit from the length using \strip@pt as shown below. I you want the number in cm you would have to convert it by yourself. \documentclass{article} \makeatletter \newcommand*{\getlength}[1]{\strip@pt#1} % Or rounded back to `cm` (there will be some rounding errors!) %\newcommand*{\getlength}[1]{\strip@pt\dimexpr0.035146\dimexpr#1\relax\...


19

For normal LaTeX usage and few lengths in points or other fixed unit I would recommend the usage of dimension registers (LaTeX: length, TeX: \dimen). Their benefit is that they are faster, already terminated and can be prefixed with a factor. The drawback is that you need to allocate the register and must be careful not to use it on its own inside a text. ...


Only top voted, non community-wiki answers of a minimum length are eligible