1

I'm using the following code to show two tikzpictures in a line.

\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage[labelformat=empty]{caption}
\begin{document}
\begin{center}
    \begin{minipage}[b]{.5\textwidth}
        \centering
        \begin{tikzpicture}
        \draw (0,2) -- (0,-2);
        \end{tikzpicture}
        \captionof{figure}{
            A non-essential apartment\\ 
            of type $A_1$.}
        \end{minipage}%
        \begin{minipage}[b]{.5\textwidth}
        \centering
        \begin{tikzpicture}
            \foreach \x in {0,0.6,1.2,1.8}
                \draw (\x,2)--(\x,-2) (2,\x)--(-2,\x) (-\x,2)--(-\x,-2) (2,-\x)--(-2,-\x);
        \end{tikzpicture}
        \captionof{figure}{
            A non-irreducible apartment\\ 
            of type $A_1\times A_1$.}
        \end{minipage}
\end{center}
\end{document}

However, it shows as following enter image description here

Why the second captionof is not centered?

Update: shorten the text in second captionof to show the problem more clear.

0

1 Answer 1

3

enter image description here

the first caption, without the \\ would fit on a single line, this causes a different route to be taken, but then finally the \\ is executed in the scope of centering and the lines are centred.

The second caption does not fit on a line so is set in a parbox.

Here I used the caption package setup command to skip the check for single line, so both captions are treated the same way. If you want the captions to be centred in their parbox (or have just the last line of a justified caption centred, the caption package has options for that.

enter image description here

\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage[labelformat=empty]{caption}
\begin{document}
\begin{center}
\captionsetup{singlelinecheck=off,justification=centerlast}
\begin{minipage}[b]{.5\textwidth}
        \centering
        \begin{tikzpicture}
        \draw (0,2) -- (0,-2);
        \end{tikzpicture}
        \captionof{figure}{
            A non-essential apartment\\
            of type $A_1$.}
        \end{minipage}%
        \begin{minipage}[b]{.5\textwidth}
        \centering
        \begin{tikzpicture}
            \foreach \x in {0,0.6,1.2,1.8}
                \draw (\x,2)--(\x,-2) (2,\x)--(-2,\x) (-\x,2)--(-\x,-2) (2,-\x)--(-2,-\x);
        \end{tikzpicture}
        \captionof{figure}{
            A non-irreducible essential apartment
            of type $A_1\times A_1$.}
        \end{minipage}
\end{center}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .