根据特定数学符号对齐表格列

根据特定数学符号对齐表格列

我确实有一个longtabu\newglossarystyle它 原本是glossaries符号列表,但我为 MWE 提取了它。第一列显示数学运算符,第二列显示它们的描述。如您所见,第一列看起来相当混乱。如果第一列以括号为中心会更好。是否有可能自动实现这一点?

在此处输入图片描述

我已经尝试过\hphantoms,但这需要大量手动工作,并且在全球范围内无效。要将列对齐到小数点或其他符号dcolumn包,但我无法得到我想要的结果。我尝试的最后一件事是简单地放入定义\begin{longtabu} to \linewidth {r@{${}\left(\phantom{a}\right){}$}lX}longtabumulticolumn在不需要括号的地方使用。但对齐也是不正确的。

是否有一种自动化的方法来实现括号内第一列的对齐?


原始 MWE

\documentclass{article}

\usepackage{longtable}
\usepackage{tabu}

\newcommand*\dif{\mathop{}\!\mathrm{d}}

\begin{document}

\begingroup
\renewcommand{\arraystretch}{1.4}
\begin{longtabu} to \linewidth {cX}
Symbol                                      & Description   \tabularnewline
$\bar{\left(\phantom{a}\right)}$            & Operator 1    \tabularnewline
$\dif\left(\phantom{a}\right)$              & Operator 2    \tabularnewline
$\dot{\left(\phantom{a}\right)}$            & Operator 3    \tabularnewline
$\left(\phantom{a}\right)_{,x}$             & Operator 4    \tabularnewline
$\hat{\left(\phantom{a}\right)}$            & Operator 5    \tabularnewline
$\left(\phantom{a}\right)^{-1}$             & Operator 6    \tabularnewline
$\partial\left(\phantom{a}\right)$          & Operator 7    \tabularnewline
$\left(\phantom{a}\right)^T$                & Operator 8    \tabularnewline
\end{longtabu}
\endgroup

\end{document}

尝试 1

多列的居中方向弄乱了这些线条。

\documentclass{article}

\usepackage{longtable}
\usepackage{tabu}

\newcommand*\dif{\mathop{}\!\mathrm{d}}

\begin{document}

\begingroup
\renewcommand{\arraystretch}{1.4}
\begin{longtabu} to \linewidth {r@{${}\left(\phantom{a}\right){}$}lX}
\multicolumn{2}{c}{Symbol}                           & Description   \tabularnewline
\multicolumn{2}{c}{$\bar{\left(\phantom{a}\right)}$} & Operator 1    \tabularnewline
$\dif$                                              && Operator 2    \tabularnewline
\multicolumn{2}{c}{$\dot{\left(\phantom{a}\right)}$} & Operator 3    \tabularnewline
&$_{,x}$                                             & Operator 4    \tabularnewline
\multicolumn{2}{c}{$\hat{\left(\phantom{a}\right)}$} & Operator 5    \tabularnewline
&$^{-1}$                                             & Operator 6    \tabularnewline
$\partial$                                          && Operator 7    \tabularnewline
&$^T$                                                & Operator 8    \tabularnewline
\end{longtabu}
\endgroup

\end{document}

第二次尝试

基本上没问题,但不适用于在定义\newglossaryentry中使用这个的上下文glossaries

\documentclass{article}

\usepackage{longtable}
\usepackage{tabu}

\newcommand*\dif{\mathop{}\!\mathrm{d}}

\begin{document}

\begingroup
\renewcommand{\arraystretch}{1.4}
\begin{longtabu} to \linewidth {r@{}c@{}lX}
\multicolumn{3}{c}{Symbol}                              & Description   \tabularnewline
           & $\bar{\left(\phantom{a}\right)}$ &         & Operator 1    \tabularnewline
$\dif$     & $\left(\phantom{a}\right)$       &         & Operator 2    \tabularnewline
           & $\dot{\left(\phantom{a}\right)}$ &         & Operator 3    \tabularnewline
           & $\left(\phantom{a}\right)$       & $_{,x}$ & Operator 4    \tabularnewline
           & $\hat{\left(\phantom{a}\right)}$ &         & Operator 5    \tabularnewline
           & $\left(\phantom{a}\right)$       & $^{-1}$ & Operator 6    \tabularnewline
$\partial$ & $\left(\phantom{a}\right)$       &         & Operator 7    \tabularnewline
           & $\left(\phantom{a}\right)$       & $^T$    & Operator 8    \tabularnewline
\end{longtabu}
\endgroup

\end{document}

在此处输入图片描述

我设法将此方案应用于词汇表。但这似乎需要大量手动工作:

符号定义:

\newglossary[slg7]{operatorlist}{syi7}{syg7}{Operators}
% compile with: makeindex -s %S.ist -t %S.slg7 -o %S.syi7 %S.syg7

\newglossaryentry{symb:operator:bar}{%
  symbol      ={$\bar{\left(\phantom{a}\right)}$},%
  name        ={},%
  description ={Value in material coordinate system},%
  user1       ={},%
  user2       ={$\protect\bar{\protect\left(\protect\phantom{a}\protect\right)}$},%
  user3       ={},%
  type        =operatorlist,%
  sort        =olocalbar,%
}

\newglossaryentry{symb:operator:dif}{%
  symbol      ={$\dif\left(\phantom{a}\right)$},%
  name        ={},%
  description ={Differential operator},%
  user1       ={$\protect\dif$},%
  user2       ={$\protect\left(\protect\phantom{a}\protect\right)$},%
  user3       ={},%
  type        =operatorlist,%
  sort        =odifdifferential,%
}

\newglossaryentry{symb:operator:dx}{%
  symbol      ={$\left(\phantom{a}\right)_{,x}$},%
  name        ={},%
  description ={Spatial derivative with respect to coordinate $x$},%
  user1       ={},%
  user2       ={$\protect\left(\protect\phantom{a}\protect\right)$},%
  user3       ={$_{,x}$},%
  type        =operatorlist,%
  sort        =odifdx,%
}

glossaries风格:

\newglossarystyle{myoperatorstyle}{%
  \renewcommand*{\glsclearpage}{}%
  \renewenvironment{theglossary}%
    {%
      \begingroup%
      \renewcommand{\arraystretch}{1.4}%
      \begin{longtabu} to \linewidth {@{\ \;}r@{}c@{}lX}
    }%
    {%
      \end{longtabu}
      \endgroup
    }%
  % Header line
  \renewcommand*{\glossaryheader}{%
    \multicolumn{3}{@{}c}{\textbf{Symbol}} & \textbf{Description}%
    \tabularnewline%
    \tabularnewline%
    \endhead%
    \endfoot%
  }%
  % indicate what to do at the start of each logical group
  \renewcommand*{\glsgroupskip}{\tabularnewline}% What to do between groups
  % entry
  \renewcommand*{\glossentry}[1]{%
    \glsentryitem{##1}% Entry number if required
    \glsentryuseri{##1} &
    \glsentryuserii{##1} &
    \glsentryuseriii{##1} &
    \glossentrydesc{##1}
    \tabularnewline%
  }%
}

打印词汇表:

\printglossary[type=operatorlist,style=myoperatorstyle,nonumberlist]

答案1

您可以使用eqparbox包来完成此操作。为此,我定义了一个tpsymb命令(三部分符号),如您所见,它有 3 个参数:一个“前符号”,一个主符号(在整个文件中必须相同)和一个“后符号”。前部分和后部分放在 中\eqmakebox,这样每个前部分都具有相同的宽度,后部分也是如此。

\documentclass{article}

\usepackage{longtable}
\usepackage{tabu}
\usepackage{ eqparbox}

    \newcommand\eqmathbox[2][M]{\eqmakebox[#1][l]{$\displaystyle#2$}}

\newcommand*\dif{\mathop{}\!\mathrm{d}}
\newcommand\tpsymb[3]{\eqmakebox[pre][r]{\ensuremath{#1}}\ensuremath{#2}\eqmakebox[post][l]{\ensuremath{#3}}}

%\newcommand\mysymbol
\begin{document}

\begingroup
\renewcommand{\arraystretch}{1.4}
\noindent
\begin{longtabu} to \linewidth {cX}
Symbol & Description \tabularnewline
\tpsymb{}{\bar{\left(\phantom{a}\right)}}{} & Operator 1 \tabularnewline
\tpsymb{\dif}{\left(\phantom{a}\right)}{} & Operator 2 \tabularnewline
\tpsymb{}{\dot{\left(\phantom{a}\right)}}{} & Operator 3 \tabularnewline
\tpsymb{}{\left(\phantom{a}\right)}{_{,x}} & Operator 4 \tabularnewline
\tpsymb{}{\hat{\left(\phantom{a}\right)}}{} & Operator 5 \tabularnewline
\tpsymb{}{\left(\phantom{a}\right)}{^{-1}} & Operator 6 \tabularnewline
\tpsymb{\partial}{\left(\phantom{a}\right)}{} & Operator 7 \tabularnewline
\tpsymb{}{\left(\phantom{a}\right)}{^T} & Operator 8 \tabularnewline
\end{longtabu}
\endgroup

\end{document} 

在此处输入图片描述

答案2

这主要是美学问题。即使数学符号位于字段的中心,它们也不会居中。您需要做的是确定您真正想要居中的内容,然后调整对齐点以使其居中。

在本例中,我将 居中$(a)$。这是通过测量最宽字段的宽度 ( Symbol) 和 的宽度$(a)$并将\hspace*{\fixup}(您也可以使用\makebox[\fixup][r]{...})添加到左列来实现的。

\documentclass{article}

\usepackage{longtable}
\usepackage{tabu}

\newcommand*\dif{\mathop{}\!\mathrm{d}}

\newlength{\fixup}

\begin{document}

\settowidth{\dimen0}{Symbol}%
\settowidth{\dimen1}{$(a)$}%
\setlength{\fixup}{\dimexpr 0.5\dimen0 - 0.5\dimen1}%

\begingroup
\renewcommand{\arraystretch}{1.4}
\begin{longtabu} to \linewidth {r@{}lX}
\multicolumn{2}{c}{Symbol}              & Description   \tabularnewline
\hspace*{\fixup}% force alignment point to center $(a)$
&$\bar{(\phantom{a})}$    & Operator 1    \tabularnewline
$\dif$&$(\phantom{a})$                  & Operator 2    \tabularnewline
&$\dot{(\phantom{a})}$                  & Operator 3    \tabularnewline
&$(\phantom{a})_{,x}$                   & Operator 4    \tabularnewline
&$\hat{(\phantom{a})}$                  & Operator 5    \tabularnewline
&$(\phantom{a})^{-1}$                   & Operator 6    \tabularnewline
$\partial$&$(\phantom{a})$              & Operator 7    \tabularnewline
&$(\phantom{a})^T$                      & Operator 8    \tabularnewline
\end{longtabu}
\endgroup

\end{document}

演示

相关内容