基于文本和图形的表格对齐,我的问题是如何使t
构成表格的所有 3 个元素对齐。c
和可以正常工作,但 不行。 b
t
c
b
\documentclass[10pt,a4paper]{scrartcl}
\usepackage[pass,showframe]{geometry}
\usepackage{graphicx}
\usepackage{array}
\usepackage{varwidth}
\newcommand*{\mtab}[2][]{\begin{tabular}[#1]{@{}l@{}} #2 \end{tabular}}
\newcommand*{\pbox}[2][c]{\mtab[#1]{\begin{varwidth}[#1]{\linewidth}#2\end{varwidth}}}
\newcommand*{\Logo}{\includegraphics[width=\linewidth]{example-image}}
\begin{document}
\begingroup
\noindent
\begin{tabular}{@{}p{0.15\textwidth}<{\hfill}>{\centering}p{0.5\textwidth}>{\hfill}p{\dimexpr 0.35\textwidth-4\tabcolsep\relax}@{}}
\pbox[b]{\raisebox{\dimexpr-\height+\ht\strutbox\relax}{\Logo}} & \pbox[b]{aaa\\ bbb\\ ccc\\ ddd} & \pbox[b]{eee\\ fff\\ hhh hhh hhh hhh hhh hhh}
\end{tabular}
\endgroup
\end{document}
答案1
您有这么多嵌套框;很难说您希望它们都用于什么目的。我也不确定为什么您需要一个表格环境来实现这一切。也许,如果您能更清楚地说明这一需求,我就可以给您一个更好的答案。
另外,你似乎以为框和表格环境的对齐命令是相互关联的。其实不然。对齐命令是相对于每个框的基线的。坐在我发布的 MWE 中,我构造了一条红线来显示基线的位置以及其他所有内容如何与基线对齐。
下面是一个大大减少框数量的示例。然后,我说明了对齐各种元素的不同方法:要么通过对齐参数,要么tabular
通过使用\raisebox
及其访问其工作的框的尺寸的能力。
\documentclass{article}
%..%
\usepackage[showframe]{geometry}
\usepackage{graphicx}
\usepackage{xcolor}
\pagestyle{empty}
%..%
\setlength{\fboxsep}{0pt}
\setlength{\parindent}{0pt}
%..%
\newcommand{\showbaseline}{\makebox[0pt][l]{\color{red!60}\hspace*{-1cm}\rule[-0.1pt]{\dimexpr\linewidth+2cm}{0.1pt}}}
\begin{document}
There are way too many boxes:
\noindent
\showbaseline%
\begin{minipage}[t]{0.15\textwidth}
\raisebox{-0.5\height}%
{\includegraphics[width=\linewidth]{example-image}}
\end{minipage}%
\hspace*{\fill}%
\raisebox{0pt}{%
\begin{minipage}[t]{0.5\textwidth}
\hspace*{\fill}
\fbox{\begin{tabular}[b]{@{}l@{}}
aqaa\\ bbb\\ cycc\\ dydd
\end{tabular}}
\hspace*{\fill}
\end{minipage}}%
\hspace*{\fill}%
\begin{minipage}[t]{\dimexpr 0.35\textwidth}
\hspace*{\fill}
\fbox{\begin{tabular}[b]{@{}l@{}}
fff\\ hhh
\end{tabular}}
\end{minipage}%
\vspace{\fill}
%-@-(1)---------------------------------------------------------------------
Similar, but with far fewer boxes: I say \emph{similar} because I'm using
\verb-\hspace*{\stretch{...}}- to achieve part of the effect of your box widths.
\noindent
\showbaseline%
\raisebox{-0.5\height}%
{\includegraphics[width=0.15\linewidth]{example-image}}
\hspace*{\stretch{1}}%
\fbox{\begin{tabular}[b]{@{}l@{}}
aqaa\\ bbb\\ cycc\\ dydd
\end{tabular}}
\hspace*{\stretch{2.45}}%
\fbox{\begin{tabular}[c]{@{}l@{}}
fff\\ hhh
\end{tabular}}
\vspace{\fill}
%-@-(2)---------------------------------------------------------------------
A different alignment.
\noindent
\showbaseline%
\raisebox{-\height}%
{\includegraphics[width=0.15\linewidth]{example-image}}
\hspace*{\stretch{1}}%
\fbox{\begin{tabular}[t]{@{}l@{}}
aqaa\\ bbb\\ cycc\\ dydd
\end{tabular}}
\hspace*{\stretch{2.45}}%
\fbox{\begin{tabular}[b]{@{}l@{}}
fff\\ hhh
\end{tabular}}
\vspace{\fill}
%-@-(3)---------------------------------------------------------------------
Another alignment: notice the added \verb-\raisebox- to get the first
\verb-tabular- to completely sit on the baseline and the last
\verb-tabular- environment below the baseline. This is because
\verb-\raisebox- has access to the dimensions of the boxes it's working on.
\noindent
\showbaseline%
% not raising the graphics%\raisebox{-\height}%
{\includegraphics[width=0.15\linewidth]{example-image}}
\hspace*{\stretch{1}}%
\raisebox{\depth}{%
\fbox{\begin{tabular}[c]{@{}l@{}}
aqaa\\ bbb\\ cycc\\ dydd
\end{tabular}}}
\hspace*{\stretch{2.45}}%
\raisebox{-\height}{%
\fbox{\begin{tabular}[t]{@{}l@{}}
fff\\ hhh
\end{tabular}}}
\end{document}
当然,通过嵌套盒子,你可以实现各种效果在对齐方面。 但是,你也可以让事情变得更加复杂,因为你实际上创建了多个基线:主要的文本的基线和你正在使用的每个框内的基线。这可能会对你不利。而且,我相信这就是导致你沮丧的原因。