到目前为止,我看到的大多数指示似乎都表明该指示m
是用于垂直居中放置单元格内容,但对我而言却不起作用。这就是我所拥有的
\begin{table}[htb]
\centering
\sffamily \begin{tabularx}{1.0\textwidth}{ m{3cm} p{5.5cm} p{5.5cm} }
\hline
&
\textbf{Helpful}
&
\textbf{Harmful}
\hfill \\ \hline
\textbf{Internal origin} \\ (organization) &
Item 1
~\textbullet~ Item 2
~\textbullet~ Item 3
~\textbullet~ Item 4
~\textbullet~ Item 5
~\textbullet~ Item 6
~\textbullet~ Item 7
~\textbullet~ Item 8
~\textbullet~ Item 9
&
Item 1
~\textbullet~ Item 2
~\textbullet~ Item 3
~\textbullet~ Item 4
~\textbullet~ Item 5
~\textbullet~ Item 6
~\textbullet~ Item 7
~\textbullet~ Item 8
~\textbullet~ Item 9
\\
\hline
\textbf{External origin} \\ (environment) &
Item 1
~\textbullet~ Item 2
~\textbullet~ Item 3
~\textbullet~ Item 4
~\textbullet~ Item 5
~\textbullet~ Item 6
~\textbullet~ Item 7
~\textbullet~ Item 8
~\textbullet~ Item 9
&
Item 1
~\textbullet~ Item 2
~\textbullet~ Item 3
~\textbullet~ Item 4
~\textbullet~ Item 5
~\textbullet~ Item 6
~\textbullet~ Item 7
~\textbullet~ Item 8
~\textbullet~ Item 9
\\
\hline
\end{tabularx} \normalfont
\caption{SWOT matrix}
\label{tab:swot-matrix}
\end{table}
我希望左侧的单元格垂直居中,顶部的单元格水平居中。我怎样才能做到这一点?
看起来很奇怪,您需要m
在不想居中的列上指定一个-column。这里的动机是-m
列在单元格的中间(垂直)设置锚点,就像-p
列在第一行的基线处(再次,垂直)设置锚点一样。因此,将第二列和第三列(垂直较高)设置为-m
列将使它们相对于其他列垂直居中。
\documentclass{article}
\usepackage[margin=1cm]{geometry}% Just for this example
\usepackage{tabularx,array,booktabs}
\newenvironment{shortlist}
{\renewcommand{\item}{\renewcommand{\item}{\unskip\space\textbullet~}}}
{}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{document}
\noindent\sffamily
\begin{tabularx}{\textwidth}{ m{3cm} X X }
\toprule
& \multicolumn{1}{c}{\textbf{Helpful}} & \multicolumn{1}{c}{\textbf{Harmful}} \\
\midrule
\textbf{Internal origin} \\ (organization) &
\begin{shortlist}
\item Item 1 \item Item 2 \item Item 3 \item Item 4 \item Item 5
\item Item 6 \item Item 7 \item Item 8 \item Item 9
\end{shortlist}
&
\begin{shortlist}
\item Item 1 \item Item 2 \item Item 3 \item Item 4 \item Item 5
\item Item 6 \item Item 7 \item Item 8 \item Item 9
\end{shortlist}
\\
\textbf{External origin} \\ (environment) &
\begin{shortlist}
\item Item 1 \item Item 2 \item Item 3 \item Item 4 \item Item 5
\item Item 6 \item Item 7 \item Item 8 \item Item 9
\end{shortlist}
&
\begin{shortlist}
\item Item 1 \item Item 2 \item Item 3 \item Item 4 \item Item 5
\item Item 6 \item Item 7 \item Item 8 \item Item 9
\end{shortlist}
\\
\bottomrule
\end{tabularx}
\end{document}
如果将来会发生这种情况,我已经对编码样式进行了一些小的调整,所有这些调整都是为了更一致地使用和易于更改。也就是说,我删除了一些硬编码\textbullet
和空格的内容,并替换为可以在需要时全局更改的环境。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句