![使用表格进行顶部对齐/垂直对齐时遇到困难](https://linux22.com/image/438583/%E4%BD%BF%E7%94%A8%E8%A1%A8%E6%A0%BC%E8%BF%9B%E8%A1%8C%E9%A1%B6%E9%83%A8%E5%AF%B9%E9%BD%90%2F%E5%9E%82%E7%9B%B4%E5%AF%B9%E9%BD%90%E6%97%B6%E9%81%87%E5%88%B0%E5%9B%B0%E9%9A%BE.png)
我无法将左列的内容与表格单元格的顶部对齐。我尝试使用\begin{tabular}[t]{|l|l|}
,正如大多数其他帖子所建议的那样,但未能成功修复它。请帮忙。
以下是我的代码,供参考:
\documentclass{article}
\usepackage{makecell}
\begin{document}
\begin{table}
\centering
\begin{tabular}[t]{|l|l|}
\hline
\textbf{Fact Finding Heading} & \textbf{Stakeholder issues} \\\hline
Materials / Supply Chain / Manufacturing & \makecell[l]{1. \\ 2. \\ 3. \\} \\\hline
Environment & \makecell[l]{1. \\ 2. \\ 3. \\} \\\hline
Society & \makecell[l]{1. \\ 2. \\ 3. \\} \\\hline
Energy & \makecell[l]{1. \\ 2. \\ } \\\hline
Regulations & \makecell[l]{1. \\ 2. \\ } \\\hline
Economy & \makecell[l]{1. \\ 2. \\ } \\\hline
\end{tabular}
\caption{Caption}
\label{tab:my_label}
\end{table}
\end{document}
谢谢
以下是供参考的输出。(我希望左列的文本位于左上角)
答案1
这是一个常见问题,因为您需要对t
右列条目进行操作对齐。可以将其视为设置单元格的锚点。下面我使用以下方法调整了美观性booktabs
,但即使你最终不使用它,原理仍然是一样的:
\documentclass{article}
\usepackage{makecell,booktabs}
\begin{document}
\begin{tabular}{ l l }
\toprule
\textbf{Fact Finding Heading} & \textbf{Stakeholder issues} \\
\midrule
\makecell[lt]{Materials / \\
Supply Chain / \\
Manufacturing} & \makecell[lt]{1. \\ 2. \\ 3.} \\
\addlinespace
Environment & \makecell[lt]{1. \\ 2. \\ 3.} \\
\addlinespace
Society & \makecell[lt]{1. \\ 2. \\ 3.} \\
\addlinespace
Energy & \makecell[lt]{1. \\ 2.} \\
\addlinespace
Regulations & \makecell[lt]{1. \\ 2.} \\
\addlinespace
Economy & \makecell[lt]{1. \\ 2.} \\
\bottomrule
\end{tabular}
\end{document}
答案2
tabularx
以下是使用和组合的替代booktabs
方法enumitem
:
\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{enumitem}
\newlist{tabenum}{enumerate}{1}
\setlist[tabenum]{label*=\arabic*.,
leftmargin=*,
nosep,
before=\begin{minipage}[t]{\hsize},
after=\end{minipage}}
\begin{document}
\begin{table}
\centering
\begin{tabularx}{\linewidth}{p{4.25cm}X}
\toprule
Fact Finding Heading & Stakeholder issues \\
\midrule
Materials / Supply Chain / Manufacturing & \begin{tabenum}
\item A longer line of text that gets automatically broken over multiple lines.
\item text
\item text
\end{tabenum} \\ \addlinespace
Environment & \begin{tabenum}
\item text
\item text
\item text
\end{tabenum}\\ \addlinespace
Society & \begin{tabenum}
\item text
\item text
\item text
\end{tabenum} \\ \addlinespace
Energy & \begin{tabenum}
\item text
\item text
\end{tabenum} \\ \addlinespace
Regulations & \begin{tabenum}
\item text
\item text
\end{tabenum} \\ \addlinespace
Economy & \begin{tabenum}
\item text
\item text
\end{tabenum} \\
\bottomrule
\end{tabularx}
\caption{Caption}
\label{tab:my_label}
\end{table}
\end{document}
答案3
tblr
在以下环境下,一切变得简单tabularray
包:您不再需要\makecell
命令和makecell
包。
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{table}
\centering
\begin{tblr}[t]{|l|l|}
\hline
\textbf{Fact Finding Heading} & \textbf{Stakeholder issues} \\\hline
Materials / Supply Chain / Manufacturing & {1. Text\\ 2. Text\\ 3. Text} \\\hline
Environment & {1. Text\\ 2. Text\\ 3. Text} \\\hline
Society & {1. Text\\ 2. Text\\ 3. Text} \\\hline
Energy & {1. Text\\ 2. Text} \\\hline
Regulations & {1. Text\\ 2. Text} \\\hline
Economy & {1. Text\\ 2. Text} \\\hline
\end{tblr}
\caption{Caption}
\label{tab:my_label}
\end{table}
\end{document}