
私はテーブル内で垂直方向の中央揃えをしようとしていますが、特定のコンポーネントを中央揃えにしています。私は LaTeX をアルゴリズム的に生成しているので、これを一般的な方法で実行したいと考えています。
MWE は次のとおりです。
\documentclass[a4paper, 10pt]{scrartcl}
\usepackage{soul}
\usepackage[cm]{fullpage}
\usepackage{array}
\usepackage{tikz}
\begin{document}
\thispagestyle{empty}
\begin{center}
% Table for row 1, which has 2 columns.
%\begin{table}[h]
\begin{tabular}{>{\centering\arraybackslash}m{7cm}l>{\centering\arraybackslash}m{4cm}}
% SHAPE: rect
\parbox[c][4.4cm][c]{7cm}{\begin{tikzpicture}
% *** RECTANGLE FOR ROW 1, COLUMN 1 *******
\draw (0cm,0cm) -- (0cm,4cm) -- (7cm,4cm) -- (7cm,0cm) -- cycle;
\end{tikzpicture}
\center first}
& \hspace{1cm} & % SHAPE: rect
\parbox[c][3.4cm][c]{4cm}{\begin{tikzpicture}
% *** RECTANGLE FOR ROW 1, COLUMN 2 *******
\draw (0cm,0cm) -- (0cm,3cm) -- (4cm,3cm) -- (4cm,0cm) -- cycle;
\end{tikzpicture}
\center second}
\\
\end{tabular}
\end{center}
\end{document}
これは次のものを生成します:
この目的は、垂直方向に中央揃えにすることです (境界ボックスの問題のため、完璧に機能していないようです)。
しかし、私が本当に望んでいるのは、tikzボックスを垂直に並べることです彼らの中央に配置しますが、テキストは上の図のようにボックスの真下に垂れ下がったままです。わかりやすくするために、ボックスを次のように垂直中央で揃えます (点線は視線を誘導するためのものです)。
答え1
このような:
\documentclass[a4paper, 10pt]{scrartcl}
\usepackage{soul}
\usepackage[cm]{fullpage}
\usepackage{array}
\usepackage{tikz}
\begin{document}
\thispagestyle{empty}
\begin{center}
% Table for row 1, which has 2 columns.
\begin{tabular}{>{\centering\arraybackslash}m{7cm}l>{\centering\arraybackslash}m{4cm}}
% SHAPE: rect
\begin{tikzpicture}
% *** RECTANGLE FOR ROW 1, COLUMN 1 *******
\draw (0,0) rectangle (7,4);
\draw [red,dotted] (0,2) -- (7,2);
\end{tikzpicture}\begin{center}
first
\end{center}
& \hspace{1cm} & % SHAPE: rect
\begin{tikzpicture}
% *** RECTANGLE FOR ROW 1, COLUMN 2 *******
\draw (0,0) rectangle (4,3);
\draw [red,dotted] (0,1.5) -- (4,1.5);
\end{tikzpicture}\begin{center}
second
\end{center}\\
\end{tabular}
\end{center}
\end{document}
アップデート:
前にこれについて言及しておくべきでした。実際には、列指定子の>{\centering\arraybackslash}
前には必要ありません。列指定子は、デフォルトで、行の残りの部分と比例して、各エントリをセル内で垂直方向と水平方向に中央揃えします。したがって、画像のみがある場合は、画像は常にセル内で中央揃えになります (水平方向と垂直方向の両方)。ただし、画像の下のテキストが問題を引き起こす可能性があります。コンテンツ全体が垂直方向に中央揃えされているため、テキストが異なる行を占めると、画像がオフセットされます。画像を再び中央揃えにするには、下のテキストが同じ行を占めるようにする必要があります (たとえば、空行を作成します)。次に例を示します。m
m
tikz
\documentclass[a4paper, 10pt]{scrartcl}
\usepackage{soul}
\usepackage[cm]{fullpage}
\usepackage{array}
\usepackage{tikz}
\begin{document}
\thispagestyle{empty}
\begin{center}
% Table for row 1, which has 2 columns.
\begin{tabular}{|m{7cm}|l|m{4cm}|}
% SHAPE: rect
\begin{tikzpicture}
% *** RECTANGLE FOR ROW 1, COLUMN 1 *******
\draw (0,0) rectangle (7,4);
\draw [red,dotted] (0,2) -- (7,2);
\end{tikzpicture}\begin{center}
first
\end{center}
& \hspace{1cm} & % SHAPE: rect
\begin{tikzpicture}
% *** RECTANGLE FOR ROW 1, COLUMN 2 *******
\draw (0,0) rectangle (4,3);
\draw [red,dotted] (0,1.5) -- (4,1.5);
\end{tikzpicture}\begin{center}
second picture have long text under the picture
\end{center}\\
\end{tabular}
\end{center}
The second example centered the picure again by putting a empty line below first.
\begin{center}
%Table for row 1, which has 2 columns.
\begin{tabular}{|m{7cm}|l|m{4cm}|}
% SHAPE: rect
\begin{tikzpicture}
% *** RECTANGLE FOR ROW 1, COLUMN 1 *******
\draw (0,0) rectangle (7,4);
\draw [red,dotted] (0,2) -- (7,2);
\end{tikzpicture}\begin{center}
first\\\null%put a manually line break and empty contents for the new line
\end{center}
& \hspace{1cm} & % SHAPE: rect
\begin{tikzpicture}
% *** RECTANGLE FOR ROW 1, COLUMN 2 *******
\draw (0,0) rectangle (4,3);
\draw [red,dotted] (0,1.5) -- (4,1.5);
\end{tikzpicture}\begin{center}
second picture have long text under the picture
\end{center}\\
\end{tabular}
\end{center}
\end{document}
出力: