tcolorbox 内で multicol を使用した段落内の奇妙な垂直間隔

tcolorbox 内で multicol を使用した段落内の奇妙な垂直間隔

基本的な考え方は、画像の横にキャプションを配置し、垂直方向に中央に配置することです。tcolorboxポスターで使用されているため、環境内でこれを試しました。フレームがどれほど重要であるかはわかりませんtcolorboxが、ここではコンテナとして保持しました。

アイデアとしては、画像を 1 つの列に配置し、キャプションを別の列に配置するというものでしたが、これは\vspaceコマンドを使用してオフセットする必要があります。以下に示すように、コードはテキストの 1 行目と 2 行目の間に垂直スペースを配置し、1 行目の上には配置しません (コードでは 1 行目の上に配置されます)。

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

比較のために、コマンドの効果を示す 2 つの画像を示します\vspace

vspaceコマンドなしでの正しい動作 vspace コマンド使用時の垂直間隔がおかしい

これを回避する方法はありますか? これはバグですか、それとも機能ですか?

答え1

本当に必要な場合は、horizontalまずモードを終了して、つまり空行を使用してから を発行する必要があります。\vspace{0.5cm}

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

ここに画像の説明を入力してください

答え2

使用する場合、環境tcolorboxは必要ありません。すでに各ボックスとパーツが分割されており、並べて配置できます。multicoltcolorboxupperlower

おそらく、OP の希望する結果を得るための最も簡単な方法は、 tcolorboxlibrary\tcbsidebysideを必要とするボックス (2015-11-20 バージョン以降に存在)ですxparse。このコマンドは、ボックスを 2 つの等しい列に分割し、コンテンツが垂直方向に中央揃えになっています。

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

ここに画像の説明を入力してください

関連情報