我正在为我教授的一门课程编写实验室手册。在实验室安全章节中,我希望有一个表格GHS 象形图及其描述。我计划将其设为,longtable
以便在需要时可以在表格内进行分页。但是,当我这样做时,我只能让第二列中的描述文本与图形的垂直中心对齐(使用列m
)或图形的底部(使用p
或b
列)。奇怪的是,我在或p
列中得到相同的图形行为b
。我如何让第二列中的文本与图形的顶部或单元格的顶部对齐。
\documentclass{book}
\usepackage{longtable}
\usepackage{array}
\usepackage{graphicx}
\begin{document}
I expected this one to align the second column to the top of the graphic.
\begin{longtable}{|p{1in}| >{\raggedright}p{4.5in}|}\hline
p column & p column \tabularnewline \hline
\includegraphics[width=1in]{pictogram.png}
& This pictogram is for substances that have certain properties in certain situations.
This pictogram indicates a level and type of hazard or risk when using the substance.
\tabularnewline \hline
\end{longtable}
This one behaves like I expect.
\begin{longtable}{|m{1in}| >{\raggedright}p{4.5in}|}\hline
m column & p column \tabularnewline \hline
\includegraphics[width=1in]{pictogram.png}
& This pictogram is for substances that have certain properties in certain situations.
This pictogram indicates a level and type of hazard or risk when using the substance.
\tabularnewline \hline
\end{longtable}
This one behaves like I expect.
\begin{longtable}{|b{1in}| >{\raggedright}p{4.5in}|}\hline
b column & p column \tabularnewline \hline
\includegraphics[width=1in]{pictogram.png}
& This pictogram is for substances that have certain properties in certain situations.
This pictogram indicates a level and type of hazard or risk when using the substance.
\tabularnewline \hline
\end{longtable}
This one is close to what I want, but will not look correct with longer text.
\begin{longtable}{|m{1in}| >{\raggedright}b{4.5in}|}\hline
m column & b column \tabularnewline \hline
\includegraphics[width=1in]{pictogram.png}
& This pictogram is for substances that have certain properties in certain situations.
This pictogram indicates a level and type of hazard or risk when using the substance.
\tabularnewline \hline
\end{longtable}
\end{document}
答案1
\documentclass{book}
\usepackage{array, longtable}
\usepackage[export]{adjustbox}
\usepackage{graphicx}
\usepackage{lipsum}
\begin{document}
I expected this one to align the second column to the top of the graphic.
\begin{longtable}{|p{1in}| >{\raggedright}p{4.5in}|}\hline
p column & p column \tabularnewline \hline
\includegraphics[width=1in,valign=t, margin=0pt 3pt 0pt 3pt]{example-image-duck}
& This pictogram is for substances that have certain properties in certain situations.
This pictogram indicates a level and type of hazard or risk when using the substance.
\tabularnewline \hline
\includegraphics[width=1in,valign=t, margin=0pt 3pt 0pt 3pt]{example-image-duck}
& \lipsum*[1]
\tabularnewline \hline
\end{longtable}
\end{document}
编辑:
对于更短的代码(当您想插入许多图像时),您可以定义新命令,\insertimage
例如
\newcommand\insertimage[1]{\includegraphics[width=1in,valign=t, margin=0pt 3pt 0pt 3pt]{#1}}
然后你就可以把它放到你的表中
\insertimage{example-image-duck} & \lipsum*[1]