将文本置于表格列的中心?

将文本置于表格列的中心?

我有下表

\begin{tabular}{ll}
\includegraphics{tag.png} & bla bla bla.\\
\includegraphics{tag.png} & \\
\includegraphics{tag.png} & Store project\\
\includegraphics{tag.png} & Gestures\\
\includegraphics{tag.png} & Screenshot\\
\includegraphics{tag.png} & Tagging\\
\end{tabular}

现在我想实现第二列占用所有剩余的页面宽度,并且文本应在单元格中垂直居中。我实现了其中之一,但无法同时实现两者。有什么提示吗?

答案1

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{tabularx,makecell}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}

\begin{tabularx}{\linewidth}{@{} l X @{}}
\makecell{\includegraphics{tag.png}} & bla bla bla.\\
\makecell{\includegraphics{tag.png}} & \\
\makecell{\includegraphics{tag.png}} & Store project\\
\makecell{\includegraphics{tag.png}} & Gestures\\
\makecell{\includegraphics{tag.png}} & Screenshot\\
\end{tabularx}

\end{document}

答案2

使用tabularx包装:(包含垂直条只是为了显示居中)。

\documentclass{article}
\usepackage{tabularx}
\renewcommand{\tabularxcolumn}[1]{>{\centering\arraybackslash}m{#1}}
\begin{document}
\begin{tabularx}{\textwidth}{|X|X|}
 \rule{1in}{1in} & This is some text. This is some more text. This is even more text.
\end{tabularx}

\end{document}

这并没有完全满足您的要求,因为它使用了两个 X 列,而不是一个。出于某种我不明白的原因,使用

\begin{tabularx}{\textwidth}{|l|X|}

无法使X列的文本垂直居中。

答案3

Herbert 的回答是正确的。但是,如果您不想或无法指定第一列的宽度,则可以使用以下代码并自动测量。

\documentclass{article}
\usepackage{array}
\usepackage{tabularx}
\makeatletter
\newcolumntype{L}{>{\VC}l<{\endVC}}%
\renewcommand*{\tabularxcolumn}[1]{m{#1}}

\newbox\mybox
\newenvironment{VC}{%
    \begin{lrbox}{\mybox}%
}{%
    \end{lrbox}%
    \parbox[c]{\wd\mybox}{\usebox\mybox\@finalstrut\@arstrutbox}
}
\makeatother

\begin{document}
\begin{tabularx}{\textwidth}{LX}
    \rule{1in}{1in} & Text \\
    \rule{1in}{2in} & Other Text Ag\strut \\
    \rule{1in}{1in} & 
    Very very very very very very very very 
    Very very very very very very very very 
    Very very very very very very very very 
    Very very very very very very very very 
    long text \\
\end{tabularx}
\end{document}

相关内容