Hot answers tagged

382

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 ...


118

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

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{...


37

\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 ...


34

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 ...


28

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 \...


23

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 ...


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{...


21

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] \...


21

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

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

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

Setting a dimension There are several ways: LaTeX: \newcommand*{\setPKGlength}[1]{\setlength{\PKG@length}{#1}} Advantage: Package calc is automatically supported. e-TeX: \def\setPKGlength#1{\PKG@length=\dimexpr(#1)\relax} plain-TeX: \def\setPKGlength#1{\PKG@length=#1\relax} Do not forget the final \relax (see Joseph Wright's answer) Approach A (...


18

$ pdftex '\relax\showthe\dimexpr20pt + 2 cm\relax\bye' This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdftex) restricted \write18 enabled. entering extended mode > 76.9055pt. The quoting with ' assumes bash syntax, other commandlines may need different quotes, or no quotes.


18

Don't reinvent the wheel. ;-) \documentclass{article} \usepackage{centernot} \begin{document} $\centernot{\infty}$ \end{document} Some manual adjusting can help: \documentclass{article} \usepackage{centernot} \begin{document} $\centernot{\mkern-0.35mu\infty}\mkern-0.35mu$ \end{document} Finding the exact geometric center is not really easy, because ...


18

Use xfp: 7.0pt \documentclass{article} \usepackage{xfp} \begin{document} \newlength{\myLength}% \setlength{\myLength}{\fpeval{round(0.7 * \topskip, 0)}pt}% \the\myLength \end{document} Dimensions in \fpeval are converted to pt and stripped of the dimension part in order to perform calculations (hence the addition of a "closing pt"). If you want you ...


15

I recently released the quoting package which provides a consolidated environment for displayed text as an alternative to quotation and quote. As the main feature, "[f]irst-line indentation is activated by adding a blank line before the quoting environment". With regard to the question at hand: It is also possible to change left-hand and right-hand ...


15

You can use etex \dimexpr. \documentclass{standalone} \begin{document} Test \raisebox{\dimexpr-\height+\baselineskip\relax}{Test} Test \end{document}


15

By the syntax rules of TeX, any length specification allows an optional space after it which is ignored. The space is always looked for performing macro expansion, which ends when a space or another unexpandable token is found. A space token is then ignored. So \hskip1pt Then and \hskip1ptThen are perfectly equivalent (but the latter requires a tiny bit of ...


15

There is none other than doing the same thing by copying the LaTeX definition: \catcode`@=11 \newbox\@tempboxa \def\@settodim#1#2#3{\setbox\@tempboxa\hbox{{#3}}#2#1\@tempboxa \setbox\@tempboxa\box\voidb@x} \def\settoheight{\@settodim\ht} \def\settodepth {\@settodim\dp} \def\settowidth {\@settodim\wd} \catcode`@=12 Now \settowidth\mylen{xyz} would become ...


15

\kern is a TeX primitive which awaits a dimension expression, while \widthof is a calc package function which only works in \setlength and friends. It requires internal box assignments, which are not allowed in a normal dimension expression. You can't therefore use \widthof and other things like this at positions where TeX dimension expressions are awaited. ...


15

Here is an expandable test for "skips" it could be extended to dimens in a similar manner: \edef\meaningskip{\meaning\skip} \def\grabfive #1#2#3#4#5#6#7\grabfive{#2#3#4#5\ifx#6!!\fi} \def\testforskip#1{% \expandafter\ifx\csname \expandafter\grabfive\meaning#1!!!!!\grabfive\endcsname\skip \typeout{\string #1 victory}% \else \typeout{\string#1 fail =\...


15

\pgflinewidth is a length. So you can use \setlength to copy its current value: \documentclass{standalone} \usepackage{tikz} \newlength{\defaultpgflinewidth} \setlength{\defaultpgflinewidth}{\pgflinewidth} \begin{document} \begin{tikzpicture}[line width=1mm] \draw circle [radius=1cm]; \draw[line width=\defaultpgflinewidth] (-1cm,-1cm) rectangle (1cm,1cm)...


15

The recently uploaded lengthconvert package seems to be what you're looking for: \documentclass{article} \usepackage{lengthconvert} \Convertsetup{unit=in} \begin{document} \newlength{\advertwidth} \setlength{\advertwidth}{2.5in} \Convert{\advertwidth} \Convert{72.27pt} \end{document}


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