![LaTeX 表格格式](https://linux22.com/image/433223/LaTeX%20%E8%A1%A8%E6%A0%BC%E6%A0%BC%E5%BC%8F%20.png)
我是 LaTeX 的初学者,在创建表格时遇到了一个问题。标题居中,但表格却不居中。我想将它们都放在左侧。
\begin{table}[ht]
\caption{matrix D1}
\begin{tabular}{|c|c|c|c|c|}
\hline
& a & b & c & \makecell*[c]{d} \\
\hline
\makecell*[c]{a} & \color{red}0 & 1 & 100 & 10 \\
\hline
\makecell*[c]{b} & 13 & 0 & 2 &100 \\
\hline
\makecell*[c]{c} & 100 & 12 & 0 &3 \\
\hline
\makecell*[c]{d} & 4 & 100 & 11 &0 \\
\hline
\end{tabular}
\end{table}
答案1
@Bernard 评论已经解决了您的基本问题,因此建议偏离主题。您可以使用宏在单元格内容周围添加更多垂直空间\makegapedcells
:
\documentclass{article}
\usepackage{xcolor}
\usepackage{makecell}
\usepackage{caption}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document
\begin{document}
\begin{table}[ht]
\captionsetup{singlelinecheck=false}
\setcellgapes{5pt}
\makegapedcells
\caption{matrix D1}
\begin{tabular}{|*{5}{c|}}
\hline
& a & b & c & d \\
\hline
a & \textcolor{red}{0}
& 1 & 100 & 10 \\
\hline
b & 13 & 0 & 2 & 100 \\
\hline
c & 100 & 12 & 0 & 3 \\
\hline
d & 4 & 100 & 11 & 0 \\
\hline
\end{tabular}
\end{table}
\end{document}
(红线表示文字边框)