我无法使用以下代码使表格居中,但标题位于中心:
\begin{table}[h]
\centering
\resizebox{0.8\textwidth}{!}{\begin{minipage}{\textwidth}
\caption{\textbf{State Table for Example 1}}
\label{table: state table1}
\begin{tabular}{cc|cc}
x & y & X & Y \\
\hline
$\bar{0}$ & $\bar{0}$ & 1 &1 \\
0 & 1 & 0 &1 \\
$\bar{1}$ & $\bar{1}$ & 0 & 0 \\
1 & 0 & 1 &0 \\
\end{tabular}
\end{minipage}}
\end{table}
有什么建议吗?
答案1
现在它可以工作了:
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\begin{table}[h]
\centering
\resizebox{0.8\textwidth}{!}{\begin{minipage}{\textwidth}
\caption{\textbf{State Table for Example 1}}
\label{table: state table1}
\hfil % This is new
\begin{tabular}{cc|cc}
x & y & X & Y \\
\hline
$\bar{0}$ & $\bar{0}$ & 1 &1 \\
0 & 1 & 0 &1 \\
$\bar{1}$ & $\bar{1}$ & 0 & 0 \\
1 & 0 & 1 &0 \\
\end{tabular}
\end{minipage}}
\end{table}
\end{document}
答案2
box
您已将包含的外部居中,minipage
但内部的内容minipage
需要另一个\centering
:
\documentclass{article}
\usepackage{graphicx,showframe} %% showframe just for demo
\begin{document}
\begin{table}[h]
\centering %%% centers the following box
\resizebox{0.8\textwidth}{!}{\begin{minipage}{\textwidth}
\centering %% <-- this is for centering inside minipage
\caption{\textbf{State Table for Example 1}}
\label{table: state table1}
\begin{tabular}{cc|cc}
x & y & X & Y \\
\hline
$\bar{0}$ & $\bar{0}$ & 1 &1 \\
0 & 1 & 0 &1 \\
$\bar{1}$ & $\bar{1}$ & 0 & 0 \\
1 & 0 & 1 &0 \\
\end{tabular}
\end{minipage}
}
\end{table}
\end{document}