我有一张表格,我想在某些单元格中显示多行。我使用 parbox 来实现这一点,但这会使单元格中的某些项目左对齐,而有些则不对齐。如何修复此问题,使它们都以相同的方式对齐?
\documentclass{beamer}
\usepackage{multirow}
\begin{document}
\begin{frame}
\frametitle{Test page}
\resizebox{\textwidth}{!}{%
\begin{tabular}{|l||c|c|}
\hline
\multirow{3}{*} & Column one & Column two \\
\hline
\hline
Row one& \textcolor{gray}{$f(n) = n^2$} & \parbox{5cm}{$f(n) = n^2$ \\ $f(n) = n^2$}\\
Row two & \parbox{7cm}{\textcolor{gray}{$g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)})$} \\$g(n) = n^3$ } & $g(n) = n^3$\\
Row three & \textcolor{gray}{$f(n) = n^2$} & \parbox{5cm}{$f(n) = n^2$\\ $f(n) = n^2$}\\
\hline
\end{tabular}%
}
\end{frame}
\end{document}
更新。根据评论中的建议,我稍微改变了表格以显示另一个问题。
\resizebox{\textwidth}{!}{%
\begin{tabular}{|l||c|c|}
\hline
\multirow{3}{*} & Column one & Column two \\
\hline
\hline
Row one& \textcolor{gray}{$g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)})$} & \parbox{5cm}{\centering $f(n) = n^2$ \\ $f(n) = n^2$}\\
Row two & \parbox{7cm}{\textcolor{gray}{\centering $g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)})$} \\ \centering $g(n) = n^3$ } & $g(n) = n^3$\\
Row three & \textcolor{gray}{$f(n) = n^2$} & \parbox{5cm}{\centering $f(n) = n^2$\\ $f(n) = n^2$}\\
\hline
\end{tabular}%
}
g(n,S) 在“第一列”的第一行和第二行中仍然没有完全对齐。
答案1
我建议使用\multirow{}
而不是\parbox{}
。
\documentclass{beamer}
\usepackage{multirow}
\begin{document}
\begin{frame}
\frametitle{Test page}
\resizebox{\textwidth}{!}{%
\begin{tabular}{|l||c|c|}
\hline
& Column one & Column two\\
\hline
\hline
\multirow{2}{*}{Row one} & \multirow{2}{*}{$g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)})$} & $f(n) = n^2$ \\
& & $f(n) = n^2$ \\
\multirow{2}{*}{Row two} & $g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)})$ & \multirow{2}{*}{$g(n) = n^3$} \\
& $g(n) = n^3$ & \\
\multirow{2}{*}{Row three} & \multirow{2}{*}{$f(n) = n^2$} & $f(n) = n^2$\\
& & $f(n) = n^2$ \\
\hline
\end{tabular}%
}
\end{frame}
\end{document}
答案2
我建议使用 parbox
比当前设置稍窄的 es。这样,您就不必使用\resizebox
来缩小表格的大小,可以说可以使 beamer 页面更易读。
下面的代码也没有使用,\multirow
因为我看不出有什么用处。我确实插入了一些\\[2ex]
间距指令,以便在三个主要行之间获得更多的垂直间隔。
\documentclass{beamer}
\begin{document}
\begin{frame}
\frametitle{Test page}
\begin{tabular}{|l||c|c|}
\hline
& Column one & Column two \\
\hline
\hline
Row one&
\textcolor{gray}{$g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)}$} &
\parbox{2cm}{\centering $f(n) = n^2$ \\ $f(n) = n^2$}\\[2ex]
Row two & \parbox{6cm}{\textcolor{gray}{
\centering $g(n,S) = n\sqrt{\log (n/S)/\log\log(n/S)}$} \\
\centering $g(n) = n^3$ }
& $g(n) = n^3$\\[2ex]
Row three & \textcolor{gray}{$f(n) = n^2$} &
\parbox{1.75cm}{\centering $f(n) = n^2$\\ $f(n) = n^2$}\\
\hline
\end{tabular}
\end{frame}
\end{document}