![如何在 Latex 中的表格内将我的绘图和矩阵水平和垂直居中?](https://linux22.com/image/436114/%E5%A6%82%E4%BD%95%E5%9C%A8%20Latex%20%E4%B8%AD%E7%9A%84%E8%A1%A8%E6%A0%BC%E5%86%85%E5%B0%86%E6%88%91%E7%9A%84%E7%BB%98%E5%9B%BE%E5%92%8C%E7%9F%A9%E9%98%B5%E6%B0%B4%E5%B9%B3%E5%92%8C%E5%9E%82%E7%9B%B4%E5%B1%85%E4%B8%AD%EF%BC%9F.png)
我有一些用 Latex 编写的图形和矩阵,我想将它们以表格形式写入。问题是我无法将它们居中。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{angles, quotes}
\usepackage{array}
\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
\begin{document}
%PLEASE IGNORE IT. THIS IS FOR DRAWING
\newcommand{\AxisRotator}[1][rotate=0]{%
\tikz [x=0.25cm,y=0.60cm,line width=.2ex,-stealth,#1] \draw (0,0) arc (-150:150:1 and 1);%
}
%DRAWING IN LATEX
\def\x{\begin{tikzpicture}[x=0.5cm,y=0.5cm,z=0.3cm,>=stealth]
\draw[->] (xyz cs:x=0) -- (xyz cs:x=5) node[above] {$z$};
\draw[rotate=15][->] (xyz cs:x=0) -- (xyz cs:x=5) node[above] {$z1$};
\draw[->] (xyz cs:y=0) --(xyz cs:y=5) node[right] {$x$};
\draw[->] (xyz cs:z=0) --(xyz cs:z=-5) node[above] {$y$};
\draw[rotate=15][->] (xyz cs:z=0) --(xyz cs:z=-5) node[above] {$y1$};
\draw (0,0) -- (0,3) node [midway] {\AxisRotator[rotate=-90]};
\draw (1,3) node {\(\phi\)};
\end{tikzpicture}
}
\newpage
%MY TABLE STARTS FROM HERE
\begin{table}
\begin{center}
\caption{Euler Elemental Rotations}
\begin{tabular}{|p{2cm}|p{5cm}|p{6cm}|}
\hline
Axis & Euler Elemental Rotation & Rotation Matrix\\
\hline
x axis & \x & \(R_x(\phi) = \begin{bmatrix}
1 & 0 & 0\\
0 &cos\phi& -sin\phi \\
0 &sin\phi &cos\phi
\end{bmatrix} \) \\
\hline
\hline
\end{tabular}
\end{center}
\end{table}
\end{document}
如何使表格中的所有内容垂直和水平居中?
答案1
列p
类型将单元格内容沿所有行的最顶部公共基线垂直对齐。但是,对于对象tikzpicture
,默认情况下,唯一的“基线”位于底部对象的。因此,在您的示例中,看起来三个单元格实际上是在底部对齐的,而不是在顶部或中间对齐。
我可以想到两种实现格式化目标的方法。
您可以使用
m
列类型代替p
。例如,替换\begin{tabular}{|p{2cm}|p{5cm}|p{6cm}|}
和
\begin{tabular}{|m{2cm}|m{5cm}|m{6cm}|}
注意:要使用
m
列类型,array
必须加载包。幸运的是,您的测试文档中就是这种情况。您可以保留
p
列类型,但修改环境的设置tikzpicture
,以便对象的概念基线位于对象的中心而不是底部。实现此目的的一种方法是将选项添加baseline=(current bounding box.center)
到环境的可选参数中tikzpicture
。例如,更改\begin{tikzpicture}[x=0.5cm,y=0.5cm,z=0.3cm,>=stealth]
到
\begin{tikzpicture}[x=0.5cm,y=0.5cm,z=0.3cm,>=stealth, baseline=(current bounding box.center)]