问题:
尝试使用tabularx
将文本与多个图像对齐。我曾提出过类似的问题,tabular
但决定专门针对此问题提出新问题,tabularx
因为该tabular
方法产生了许多我无法解决的错误。
由于我有数字,我不知道如何对它们进行 MWE。相反,我会尝试解释问题所在。
代码:
\begin{figure}[tbh]
\begin{tabularx}{\textwidth}{cX}
\includegraphics[scale=.5]{figure8_1_server.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\
\includegraphics[width=1in]{figure8_1_database.eps} & This is some text that
describes the second figure. It will take up as much space as is needed
and will remain centred. As the text gets longer it centres in the way
that we want. So it seems that this is working. \\
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\
\includegraphics[scale=.5]{figure8_1_table.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\
\includegraphics[scale=.5]{figure8_1_row.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\
\includegraphics[scale=.5]{figure8_1_cell.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.
\end{tabularx}
\caption{Syntax för iterationen for och dess delar.}
\label{fig:database}
\end{figure}
输出:
期望的结果:
使文本与照片垂直对齐。
答案1
您需要将两列的锚点设置为垂直中心。对于c
仅包含图形的左列,您可以使用键值
valign=c
需要添加\usepackage[export]{adjustbox}
到你的序言。对于第二X
列,使用
\renewcommand{\tabularxcolumn}[1]{m{#1}}
这是您的文档,其全局设置valign=c
为全部文档中的图像:
\documentclass{article}
\usepackage[demo,export]{adjustbox}
\let\oldincludegraphics\includegraphics
\renewcommand{\includegraphics}[2][]{\oldincludegraphics[valign=c,#1]{#2}}
\usepackage{cellspace,tabularx}
\renewcommand\cellspacetoplimit{3pt}
\renewcommand\cellspacebottomlimit{3pt}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\begin{tabularx}{\textwidth}{cX}
\includegraphics[scale=.5]{figure8_1_server.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
\includegraphics[width=1in]{figure8_1_database.eps} & This is some text that
describes the second figure. It will take up as much space as is needed
and will remain centred. As the text gets longer it centres in the way
that we want. So it seems that this is working. \\\hline
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
\includegraphics[scale=.5]{figure8_1_table.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
\includegraphics[scale=.5]{figure8_1_row.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
\includegraphics[scale=.5]{figure8_1_cell.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.
\end{tabularx}
\end{document}
答案2
您可以使用
\renewcommand\tabularxcolumn[1]{m{#1}}
并且m
第一列的列类型也喜欢
\begin{tabularx}{\textwidth}{>{\centering\arraybackslash}m{2.2in}X}
要得到
您必须2.2in
按自己的意愿进行调整。顺便说一句,您的表格太长,页面放不下。
\documentclass[svgnames]{article}
\usepackage{tabu,tabularx} % just to show compatibility
\usepackage{array}
\usepackage[demo]{graphicx}
\usepackage{cellspace, makecell}
\renewcommand\cellspacetoplimit{3pt}
\renewcommand\cellspacebottomlimit{3pt}
\usepackage{xparse}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\begin{figure}[tbh]
\begin{tabularx}{\textwidth}{>{\centering\arraybackslash}m{2.2in}X}
\includegraphics[scale=.5]{figure8_1_server.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
\includegraphics[width=1in]{figure8_1_database.eps} & This is some text that
describes the second figure. It will take up as much space as is needed
and will remain centred. As the text gets longer it centres in the way
that we want. So it seems that this is working. \\\hline
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
\includegraphics[scale=.5]{figure8_1_table.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
\includegraphics[scale=.5]{figure8_1_row.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.\\\hline
\includegraphics[width=.5in]{figure8_1_arrow.eps} & \\\hline
\includegraphics[scale=.5]{figure8_1_cell.eps} & This is some text that describes the first figure. It will take up as much space as is needed and will remain centred I hope.
\end{tabularx}
\caption{Syntax för iterationen for och dess delar.}
\label{fig:database}
\end{figure}
\end{document}
我添加这些\hline
只是为了演示对齐。请删除它们。