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{figure}
\centering
\hspace*{\fill}
{ILLUSTRATION 1} \hfill {ILLUSTRATION 2}
\hspace*{\fill}
\caption{Example float with two illustrations}
\label{fig:mult1}
\end{figure}
\end{document}
However, replacing \hspace*{\fill}
with \hfill
, the space from the right margin is "gobbled":

\documentclass{article}
\usepackage{showframe}% http://ctan.org/pkg/showframe
\begin{document}
\begin{figure}
\centering
\hfill%\hspace*{\fill}
{ILLUSTRATION 1} \hfill {ILLUSTRATION 2}%
\hfill%\hspace*{\fill}
\caption{Example float with two illustrations}
\label{fig:mult1}
\end{figure}
\end{document}
giving value to the command definition for \hspace*
:
LaTeX removes horizontal space that comes at the end of a line. If you don't want LaTeX to remove this space, include the optional *
argument. Then the space is never removed.
An alternative to use if \hfill
is more intuitive than \hspace*{\fill}
, is to insert dummy text (like \null
or \mbox{}
) at the (start and) end of the line. That way the \hfill
will always have "something to infinitely stretch against":
\null\hfill%
{ILLUSTRATION 1} \hfill {ILLUSTRATION 2}%
\hfill\null%
In the above examples, showframe
merely highlighted the text block.
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 bounding boxes (cf. PGF manual v 2.10 - page 579):
As a side-effect, the path construction commands keep track of two
bounding boxes. One is the bounding box for the current path, the
other is a bounding box for all paths in the current picture.
Section 7.13 details these parameters.
What I think is happening, is that regardless of the way how the line ends (line cap
), its bounding box protrudes by \pgflinewidth
beyond the edge of the text area by this length. This is probably necessary to accommodate the whole line in case of nicely rounded line caps. Since this requires in fact .5\pgflinewidth
on each end and the bounding box of the line starts at exactly (0,0)
the overhang will be \pgflinewidth
at the end of the line.
Best Answer
\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 maintains many
\...width
parameters.\textwidth
is generally the global width of the text area, while\columnwidth
is the width of a column of text (it will be different from\textwidth
when typesetting in two or more columns). However, inside aminipage
,\textwidth
will be set to the given argument along with\hsize
,\columnwidth
, and\linewidth
(they will revert to the previous values at the end of theminipage
because it forms a group). Note that\parbox
doesn't reset\textwidth
; the size is available as\linewidth
.The parameter
\linewidth
contains the line length inside alist
(or derived) environment and it may change in a nested list (while\hsize
,\textwidth
and\columnwidth
don't change).When we have to specify a length depending on current conditions, we have to use the correct parameter. For example, the width of a figure should be specified in terms of
\columnwidth
in afigure
environment and of\textwidth
in afigure*
environment; however this is done rarely when it's known that the document will be typeset in one column format. The same should be for atabular*
ortabularx
environment.Instead, when we need something centered with respect to a line in a
list
, we should use\linewidth
:In this case it would be wrong to use
\textwidth
or\columnwidth
, as the line length is "unknown" at typing time.Notice that LaTeX uses
\hangindent
only for typesetting sectional titles and\leftskip
andrightskip
for\centering
,\raggedright
and\raggedleft
; the indentation of alist
environment is obtained via\parshape
.