考虑一个基本tabular
环境。两列,第一列必须包含tikzpicture
不确定大小的描述,第二列必须包含确定(和用户指定)宽度的描述。如果第一列的内容受到严格限制,则可以这样做:
\begin{tabular}{m{2cm}p{6cm}}
但是,第一列的内容没有得到很好的限制,因此我想知道我们是否可以实现与此相当的效果:
\begin{tabular}{mp{6cm}}
或者
\begin{tabular}{m{}p{6cm}}
第一列居中对齐,但没有宽度参数。如果需要说明,我将发布一个 mwe。
答案1
根据第一列所需的水平对齐方式,您可以简单地为第一列选择l
(左对齐)、c
(水平居中)或r
(右对齐)。这将自动适应所包含的 tikzpicture 的宽度。为了使第二列中的文本相对于 tikzpicture 垂直居中,请使用m{6cm}
第二列并将其baseline=(current bounding box.center)
作为选项添加到每个 tikzpicture。
由于此设置可能会导致表格比文本宽度更宽,因此您可能也想尝试tabularx
一下。我还在tabularx
下面的 MWE 中包含了一个示例。请注意,我将其用作\hline
眼睛的指南。在实际的表格中,我不会使用包\hline
中的线条booktabs
,或者根本不使用水平线:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usepackage{array}
\usepackage{tabularx}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\begin{tabular}{cm{6cm}}
\hline
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node[draw=black] (text1) {some text here};
\node[draw=black] (text2) [below left =of text1] {some other text here}edge [->] node {}(text1) ;
\end{tikzpicture}
& some explanatory text that is vertically centered with respect to the tikz picture\\
\hline
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node[draw=black] (text1) {A};
\node[draw=black] (text2) [below left =of text1] {B}edge [->] node {}(text1) ;
\end{tikzpicture}
& some explanatory text that is vertically centered with respect to the tikz picture\\
\hline
\end{tabular}
\bigskip
\begin{tabularx}{\textwidth}{cX}
\hline
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node[draw=black] (text1) {some text here};
\node[draw=black] (text2) [below left =of text1] {some other text here}edge [->] node {}(text1) ;
\end{tikzpicture}
& some explanatory text that is vertically centered with respect to the tikz picture\\
\hline
\begin{tikzpicture}[baseline=(current bounding box.center)]
\node[draw=black] (text1) {A};
\node[draw=black] (text2) [below left =of text1] {B}edge [->] node {}(text1) ;
\end{tikzpicture}
& some explanatory text that is vertically centered with respect to the tikz picture\\
\hline
\end{tabularx}
\end{document}