在 displaymath 內的陣列後面加上標題

在 displaymath 內的陣列後面加上標題

我正在寫這樣的真值表:

\begin{displaymath}
\begin{array}{|c c|c|}
p & q & p \land q \\
\hline
1 & 1 & 1 \\
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 0 \\
\end{array}
\end{displaymath}

我想在表格後面添加一個標題來解釋該表格是什麼。我已經嘗試過使用\captionandcaptionof但它不會編譯。

答案1

這是你想要的嗎?

\documentclass[a4paper,12pt]{article}
\usepackage{mathtools,amssymb}
\usepackage{caption}

\begin{document}

\bgroup\setlength{\belowdisplayskip}{-2ex}
\begin{gather*}
\begin{array}{|cc|c|}
p & q & p \land q \\
\hline
1 & 1 & 1 \\
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 0 \\
\end{array}
\shortintertext{%
\captionof{table}{This is my table with caption}}
\end{gather*}
\egroup
Some text. Some more text. Some more text. Some more text. Some more text.

\end{document} 

在此輸入影像描述

相關內容