2

The basic idea would be to put a caption next to an image and center it vertically. I tried this within a tcolorbox environment since it's being used on a poster. I'm not sure, how much the tcolorbox frame matters, but I kept it as container here.

The idea would have been to put the picture into one column and the caption in the other, which should be offset using a \vspace command. As shown below, the code places the vertical space between the first and second line of the text and not above the first line (where it would be in the code).

\documentclass{standalone}
\usepackage{tikz}
\usepackage{multicol}
\usepackage{tcolorbox}

\begin{document}

\begin{tcolorbox}[boxsep=-1mm]
\begin{multicols}{2} % also tried unbalanced multicols*
\begin{tikzpicture}
    \draw (0,0) -- (5,0) -- (5,4) -- (0,4) -- (0,0);
    \draw (0,0) -- (5,4);
    \draw (5,0) -- (0,4);
\end{tikzpicture}
\vspace{0.5cm} % this command causes strange vertical spacing
Figure aption. Weird vertical spacing between 1st and 2nd line, when using \textbackslash vspace command.
\end{multicols}
\end{tcolorbox}

\end{document}

For comparison, you can see two images, showing the effect of the \vspace command:

correct behavior without vspace command weird vertical spacing when using vspace command

Is there a way to circumvent this? Is this a bug or a feature?

  • it is a feature. \vspace, if used as here in horizontal mode adds the space after the paragraph has been broken into lines after the current line. a tikzpicture is just like a big letter and is part of the paragraph, it is not a display environment like a list which is set in vertical mode – David Carlisle Feb 16 '16 at 12:07
4

You have to leave the horizontal mode first, i.e. use an empty line, then issue \vspace{0.5cm}, if really needed.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{multicol}
\usepackage{tcolorbox}

\begin{document}

\begin{tcolorbox}[boxsep=-1mm]
\begin{multicols}{2} % also tried unbalanced multicols*
\begin{tikzpicture}
    \draw (0,0) -- (5,0) -- (5,4) -- (0,4) -- (0,0);
    \draw (0,0) -- (5,4);
    \draw (5,0) -- (0,4);
\end{tikzpicture}



% this command causes strange vertical spacing
\vspace{0.5cm}
Figure caption. No weird vertical spacing between 1st and 2nd line, when using \textbackslash vspace command.
\end{multicols}
\end{tcolorbox}

\end{document}

enter image description here

3

If you use tcolorbox there's no need for multicol environment, because tcolorbox already divides every box in upper and lower parts, which can be placed side by side.

Probably the easiest way to obtain OP's desired result is \tcbsidebyside box (present since 2015-11-20 version) which need xparse tcolorboxlibrary. This command already divides the box in two equal columns and the contents is vertically centered:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usepackage[skins,xparse]{tcolorbox}

\begin{document}

\tcbsidebyside[notitle,lower separated=false]{%
\begin{tikzpicture}
    \draw (0,0) -- (5,0) -- (5,4) -- (0,4) -- (0,0);
    \draw (0,0) -- (5,4);
    \draw (5,0) -- (0,4);
\end{tikzpicture}
}{%
Figure caption. Weird vertical spacing between 1st and 2nd line, when using \textbackslash vspace command.
}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.