vdots 上方无填充,完美垂直居中

vdots 上方无填充,完美垂直居中

我喜欢用来\vdots获取这样的图片(当然没有 fbox):

在此处输入图片描述

问题是\vdots不是垂直居中(高度很大),因此点在图片上的位置不正确。理想情况下,我想要一个\vdots高度合适,没有深度的 版本(以确保形状对称),这样我就可以用\raisebox{-.5\height}{\cvdots}它来围绕基线居中。

答案1

感谢 campa 的评论(谢谢!),我得出了以下多个版本:

  • 高于基线
  • 数学对齐
  • 以基线为中心
  • 水平居中于基线

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{cd}
\usetikzlibrary{backgrounds,positioning}
\usetikzlibrary{shapes,shapes.geometric,shapes.misc}
\usepackage{graphicx}

\begin{document}
\setlength{\fboxsep}{0pt}

\makeatletter
%% https://tex.stackexchange.com/questions/528774/excess-vertical-space-in-vdots/528775#528775
\DeclareRobustCommand\cvdotsAboveBaseline{%
  \vbox{\baselineskip4\p@ \lineskiplimit\z@%
    \hbox{.}\hbox{.}\hbox{.}}
}
\makeatother

\DeclareRobustCommand{\cvdotsCenterMathline}{%
  % vcenter is used to center the argument on the 'math axis', which is at half the height of an 'x', or about the position of a minus sign.
  \vcenter{\cvdotsAboveBaseline}%
}

\DeclareRobustCommand{\cvdotsCenterBaseline}{%
  \raisebox{-.5\height}{%
    $\cvdotsAboveBaseline$%
  }%
}

\DeclareRobustCommand{\chdots}{%
  \raisebox{-.5\height}{%
    \rotatebox{90}{% Maybe better options than rotatebox...
      $\cvdotsAboveBaseline$%
    }%
  }%
}

\DeclareRobustCommand{\chdotsLdots}{% Has a small space on the right and left, which chdots does not have 
  \raisebox{\dimexpr\depth-.5\totalheight\relax}{$\ldots$}%
}


\begin{tikzpicture}
  \node[fill=red] (A) {A};
  \node[fill=blue,below=of A] (B) {B};
  \path (A) -- (B) node[midway,anchor=center] {\makebox[0pt][r]{$n$ }$\cvdotsCenterMathline$};
\end{tikzpicture}

% Show baseline then vdots:
Order: Original, above baseline, aligned for math, centered on baseline, horizontal and centered on baseline (2 versions):\\
ABCp\rule{2cm}{0.1pt}\fbox{$\vdots$}\fbox{$\cvdotsAboveBaseline$}\fbox{$\cvdotsCenterMathline$}\fbox{$\cvdotsCenterBaseline$}\fbox{$\chdots$}\fbox{$\chdotsLdots$}
\end{document}

相关内容