表格中的项目符号未对齐

表格中的项目符号未对齐

我创建了下表。但是,项目符号没有对齐。我该怎么做才能使它们对齐?

\documentclass{beamer}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
\begin{document}

\begin{frame}{Symbolic Math Toolbox}
\begin{itemize}
\item Don't do nasty calculations by hand!
\item Symbolics vs. Numerics
\end{itemize}
\begin{tabular}{| p{1.3cm} | p{4cm} | p{4cm} |} \hline    & \textcolor{green}{Advantages} & \textcolor{red}{Disadvantages} \\ \hline
Symbolic & \tabitem Analytical solutions & \tabitem Sometimes can't be solved \\
 & \tabitem Lets you intuit things about solution form & \tabitem Can be overly complicated \\ \hline 
Numeric & \tabitem Always get a solution & \tabitem Hard to extract a deep understanding \\
 &\tabitem Can make solutions accurate & \tabitem Num. methods sometimes fail \\  
 & \tabitem Easy to code & \tabitem Can take a while to compute \\  \hline
 \end{tabular}
\end{frame}
\end{document}

在此处输入图片描述

答案1

使用

\newcommand\tabitem{\makebox[1em][r]{\textbullet~}}

答案2

这个答案与 @daleif 的答案在精神上相似。不同之处在于我使用宏\RaggedRight(来自ragged2e包)而不是基本\raggedright指令;不同之处在于\RaggedRight允许连字符。我还使用\newcolumntype指令来设置一种名为“P”的新列类型,该类型在 Ragged-Right 段落模式下自动设置内容。

在此处输入图片描述

\documentclass{beamer}
\usepackage{booktabs,array,ragged2e}
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}
\newcommand{\tabitem}{\textbullet~~}
\begin{document}

\begin{frame}{Symbolic Math Toolbox}
\begin{itemize}
\item Don't do nasty calculations by hand!
\item Symbolics vs.\ Numerics
\end{itemize}
\begin{tabular}{| p{1.4cm} | P{4cm} | P{4cm} |} \hline    
& \textcolor{green}{Advantages} 
& \textcolor{red}{Disadvantages} \\ \hline
Symbolic 
& \tabitem Analytical solutions 
& \tabitem Sometimes can't be solved \\
& \tabitem Lets you intuit things about solution form 
& \tabitem Can be overly complicated \\ \hline 
Numeric 
& \tabitem Always get a solution 
& \tabitem Hard to extract a deep understanding \\
& \tabitem Can make solutions accurate 
& \tabitem Num.\ methods sometimes fail \\  
& \tabitem Easy to code 
& \tabitem Can take a while to compute \\  \hline
\end{tabular}
\end{frame}
\end{document}

答案3

大概是因为~它是可拉伸的并且你的列正试图保持笔直的右边缘。

可能更好使用

\documentclass{beamer}
\usepackage{booktabs,array}% http://ctan.org/pkg/booktabs
\newcommand{\tabitem}{~~\llap{\textbullet}~~}
\begin{document}

\begin{frame}{Symbolic Math Toolbox}
\begin{itemize}
\item Don't do nasty calculations by hand!
\item Symbolics vs. Numerics
\end{itemize}
\begin{tabular}{| >{\raggedright}p{1.3cm} | >{\raggedright}p{4cm} | 
    >{\raggedright\arraybackslash}p{4cm} |} \hline &
  \textcolor{green}{Advantages} & \textcolor{red}{Disadvantages}
  \\
  \hline Symbolic & \tabitem Analytical solutions & \tabitem Sometimes
  can't be solved
  \\
  & \tabitem Lets you intuit things about solution form & \tabitem Can
  be overly complicated
  \\
  \hline Numeric & \tabitem Always get a solution & \tabitem Hard to
  extract a deep understanding
  \\
  & \tabitem Can make solutions accurate & \tabitem Num. methods
  sometimes fail
  \\
  & \tabitem Easy to code & \tabitem Can take a while to compute
  \\
  \hline
\end{tabular}
\end{frame}
\end{document}

从而将列设置为右侧不规则。请注意\arraybackslash添加到最后一列的。

答案4

这是另一个带有tabitem环境的解决方案,它实际上是一个itemize环境,因此也负责处理换行后的缩进。

不幸的是,这些软件包似乎array在环境末尾造成了一条多余的伪行tabitem,所以我没有加载这个包,因此也没有加载该ragged2e包。

我想指出的是,这个环境的定义不是我写的。我想我已经有 10 年了,但我记不清是从哪里得到的。如果有人知道,请举手,我会在这里添加来源。

\documentclass{beamer}
%\usepackage{array}
%\usepackage{ragged2e}
%    \newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}}
\usepackage{paralist}
\usepackage{booktabs}
    \newenvironment{tabitem}{%
        \vspace*{-0.5\baselineskip}%
        \setdefaultitem{\normalfont\bfseries\textbullet}%
            {\normalfont\bfseries\textendash}{}{}%
        \setdefaultleftmargin{1.1em}{1.1em}{}{}{}{}%
        \begin{compactitem}%
    }{%
        \end{compactitem}%
        \vspace*{-\baselineskip}%
    }
\begin{document}
\begin{frame}{Symbolic Math Toolbox}
\begin{itemize}
\item Don't do nasty calculations by hand!
\item Symbolics vs.\ Numerics
\end{itemize}
%% use me when using `array' and `ragged2e'
%% but unfortunately this creates a spurious blank line after the `tabitem'
%% environment
%\begin{tabular}{p{1.5cm}*{2}{P{4cm}}}
%
% therefore here the solution without these packages
\begin{tabular}{p{1.5cm}*{2}{p{4cm}}}
        \toprule
             & \textcolor{green}{Advantages}
             & \textcolor{red}{Disadvantages}                        \\
        \midrule
    Symbolic & \begin{tabitem}
                   \item Analytical solutions
                   \item Lets you intuit things about solution form
               \end{tabitem}
             & \begin{tabitem}
                   \item Sometimes can't be solved
                   \item Can be overly complicated
               \end{tabitem}                                         \\
        \midrule
    Numeric  & \begin{tabitem}
                   \item Always get a solution
                   \item Can make solutions accurate
                   \item Easy to code
               \end{tabitem}
             & \begin{tabitem}
                   \item Hard to extract a deep understanding
                   \item Num.\ methods sometimes fail
                   \item Can take a while to compute
               \end{tabitem}                                         \\
        \bottomrule
\end{tabular}
\end{frame}
\end{document}

该图显示了上述代码的结果

相关内容