
Estou tentando fazer uma centralização vertical em uma tabela, mas centralizada em um componente específico. Espero fazer isso de maneira geral porque gero o LaTeX algoritmicamente.
Aqui está um 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}
que gera isso:
A intenção disso era centralizá-lo verticalmente (o que não parece ter funcionado perfeitamente, presumo por causa de um problema de caixa delimitadora).
No entanto, o que eu realmente quero é ter as caixas tikz alinhadas verticalmentedelescentros, mas com o texto ainda pendurado diretamente abaixo da caixa, como está no diagrama acima. Para ser claro, quero as caixas alinhadas pelos seus centros verticais assim (a linha pontilhada é apenas para guiar o olho):
Responder1
Assim:
\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}
Atualizar:
Eu deveria mencionar isso antes. Na verdade, você não precisa >{\centering\arraybackslash}
antes do m
especificador de coluna. O m
especificador de coluna, por padrão, centralizará cada entrada vertical e horizontalmente dentro da proporção da célula com o resto da linha. Portanto, se você tiver apenas as tikz
imagens, elas estarão sempre alinhadas como centralizadas na célula (tanto horizontal quanto verticalmente). No entanto, o texto abaixo da imagem pode causar problemas. Se o texto tiver linhas diferentes, porque todo o conteúdo está centralizado verticalmente, a imagem ficará deslocada. Para alinhar novamente o centro da imagem, você precisa fazer com que o texto abaixo ocupe as mesmas linhas (por exemplo, fazer uma linha vazia). Aqui está um exemplo:
\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}
Saída: