为什么我无法在表格或 tikz 矩阵环境中垂直居中我的行?

为什么我无法在表格或 tikz 矩阵环境中垂直居中我的行?

这两个 MWE 都没有将行内容居中。为什么?

tabular使用环境的示例 1`

% arara: pdflatex
% arara: pdflatex
% arara: open
\documentclass[border=6pt]{standalone}

\usepackage{amsmath}
\newcommand\abs[1]{\lvert#1\rvert}

\def\aecaseA{%%
  \begin{minipage}{2in}
    \begin{gather*}
      \abs{x-y}+\abs{x}-\abs{y}
      \\= 
      2x-2y
      \end{gather*}
  \end{minipage}}

\def\aecaseB{%%
  \begin{minipage}{2in}
    \begin{gather*}
      \abs{x-y}+\abs{x}-\abs{y} 
      \\= 
      2x
    \end{gather*}
  \end{minipage}}

\def\aecaseC{%%
   No such points.
  }

\def\aecaseD{%%
  \begin{minipage}{2in}
    \begin{gather*}
      \abs{x-y}+\abs{x}-\abs{y} 
      \\= 
      0
    \end{gather*}
\end{minipage}}

\begin{document}

\begin{tabular}{ccc}
   \fbox{Case $x\geq y$} & {$y\geq 0$} & {$y<0$}    \\
   {$x\geq 0$}           & {\aecaseA}  & {\aecaseB} \\
   {$x<0$}               & {\aecaseC}  & {\aecaseD} \\
\end{tabular}

\end{document}

示例 2 使用TikZ matrix

% arara: pdflatex
% arara: pdflatex
% arara: open
\documentclass[border=6pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{matrix}

\usepackage{amsmath}
\newcommand\abs[1]{\lvert#1\rvert}

\def\aecaseA{%%
  \begin{minipage}{2in}
    \begin{gather*}
      \abs{x-y}+\abs{x}-\abs{y}
      \\= 
      2x-2y
      \end{gather*}
  \end{minipage}}

\def\aecaseB{%%
  \begin{minipage}{2in}
    \begin{gather*}
      \abs{x-y}+\abs{x}-\abs{y} 
      \\= 
      2x
    \end{gather*}
  \end{minipage}}

\def\aecaseC{%%
   No such points.
  }

\def\aecaseD{%%
  \begin{minipage}{2in}
    \begin{gather*}
      \abs{x-y}+\abs{x}-\abs{y} 
      \\= 
      0
    \end{gather*}
\end{minipage}}

\begin{document}

\begin{tikzpicture}
  \matrix[matrix of nodes,nodes={align=center,inner sep=0pt,anchor=center}]
  {
   \fbox{Case $x\geq y$} & {$y\geq 0$} & {$y<0$}    \\
   {$x\geq 0$}           & {\aecaseA}  & {\aecaseB} \\
   {$x<0$}               & {\aecaseC}  & {\aecaseD} \\
  };
\end{tikzpicture}

\end{document}

答案1

对于某些中心定义,默认的垂直对齐方式minipagec居中。

添加一条规则可能会使其更清晰:

   {$x<0$}               & {\aecaseC}

在此处输入图片描述

我猜你想消除对齐上方的空间。我觉得其中一个mathtools扩展可能会有所帮助,我可能会稍后再看……


\showbox确认您有虚假信息\abovedisplayskip,因此:

在此处输入图片描述

\documentclass[border=6pt]{standalone}

\usepackage{amsmath}
\newcommand\abs[1]{\lvert#1\rvert}

\def\aecaseA{%%
  \begin{minipage}{2in}\vspace{-\abovedisplayskip}
    \begin{gather*}
      \abs{x-y}+\abs{x}-\abs{y}
      \\= 
      2x-2y
      \end{gather*}
  \end{minipage}}

\def\aecaseB{%%
  \begin{minipage}{2in}\vspace{-\abovedisplayskip}
    \begin{gather*}
      \abs{x-y}+\abs{x}-\abs{y} 
      \\= 
      2x
    \end{gather*}
  \end{minipage}}

\def\aecaseC{%%
   No such points.
  }

\def\aecaseD{%%
  \begin{minipage}{2in}\vspace{-\abovedisplayskip}
    \begin{gather*}
      \abs{x-y}+\abs{x}-\abs{y} 
      \\= 
      0
    \end{gather*}
\end{minipage}}


\begin{document}


\begin{tabular}{ccc}
   \fbox{Case $x\geq y$} & {$y\geq 0$} & {$y<0$}    \\
   {$x\geq 0$}           & {\aecaseA}  & {\aecaseB} \\
   {$x<0$}               & {\aecaseC}  & aaa\vrule{\aecaseD} \\
\end{tabular}

\end{document}

相关内容