我正在尝试将矩阵和图像并排放置在表格格式中,使用以下代码(遵循等式旁边的图片)。
\documentclass{article}
\usepackage{amsmath}
\usepackage[font=small]{caption}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
\begin{tabular}{p{5cm}c}
{\begin{equation*}
H =
{\renewcommand{\arraystretch}{1.2}
\begin{pmatrix}
0 & 1 & 0 & 1 & 0 & 0 & 1\\
1 & 1 & 1 & 0 & 1 & 0 & 0\\
0 & 0 & 1 & 0 & 1 & 1 & 1\\
1 & 0 & 0 & 1 & 0 & 1 & 0\\
\end{pmatrix}}
\end{equation*}}
&
\includegraphics[scale=0.8]{"Tanner Graph"}
\end{tabular}
\caption{(above) parity check matrix of an $[8, 4, 4]_2$ code, and (below) the corresponding Tanner graph. Technically, this example matrix is not low-density, as it is too small}
\label{Figure 1}
\end{figure}
\end{document}
然而,当我期望看到这两个物体并排出现时,我得到的却是以下结果:
要怎么做才能达到想要的布局呢?
答案1
需要进行两项更改。首先,将矩阵从环境中移除equation*
,而是将其放置在$
分隔符之间,\displaystyle
如果需要,可以添加。这将使矩阵关于数学轴保持对称,不会插入任何换行符和空格。其次,图像原本位于基线上,必须用 包围,$\vcenter{\hbox{...}}$
以使其位于数学轴的中心。
\documentclass{article}
\usepackage{amsmath}
\usepackage[font=small]{caption}
\usepackage[demo]{graphicx}
\begin{document}
\begin{figure}[h]
\begin{tabular}{p{5cm}c}
{$\displaystyle
H =
{\renewcommand{\arraystretch}{1.2}
\begin{pmatrix}
0 & 1 & 0 & 1 & 0 & 0 & 1\\
1 & 1 & 1 & 0 & 1 & 0 & 0\\
0 & 0 & 1 & 0 & 1 & 1 & 1\\
1 & 0 & 0 & 1 & 0 & 1 & 0\\
\end{pmatrix}}
$}
&
$\vcenter{\hbox{\includegraphics[scale=0.8]{"Tanner Graph"}}}$
\end{tabular}
\caption{(above) parity check matrix of an $[8, 4, 4]_2$ code, and (below) the corresponding Tanner graph. Technically, this example matrix is not low-density, as it is too small}
\label{Figure 1}
\end{figure}
\end{document}