2

In math mode, characters and numbers are placed on the baseline and develop upward and/or downward. How can they be centered vertically around the formula axis, as symbols such as + and = are?

For example in:

\documentclass{article}
\begin{document}
$n=0\ d(C,P)$
\end{document}

The n should be shifted upward, the 0, the d, the C, the comma and the P should instead be shifted downward. How can this be done automatically without having to manually set a raisebox value for each character and/or number?

Thank you for your help, it is very appreciated.

Edit: I excuse for being unclear about what I want. To clarify, my goal is to achieve what's displayed in the image that egreg posted in his comment. I hope it is clearer now, thank you again.

13
  • 1
    Are you talking about superscript and subscript? Like ^n or _n?
    – Sigur
    Commented Nov 17, 2018 at 13:14
  • 1
    @Sigur But the slash after 0 has it a sense?
    – Sebastiano
    Commented Nov 17, 2018 at 13:15
  • Do you want to have one of them right above the other?
    – user156344
    Commented Nov 17, 2018 at 13:19
  • 2
    @EdoardoSerra I won't tell, I don't want to be considered an accomplice in crimes against typography.
    – egreg
    Commented Nov 17, 2018 at 17:00
  • 1
    @Mico The typography police might start chasing you.
    – egreg
    Commented Nov 17, 2018 at 18:32

1 Answer 1

7

The following screenshots show first what you say you want -- all letters, numerals, and commas centered vertically on the math axis -- and second what the normal typesetting approach produces, i.e., letters, numerals, and commas all placed on the baseline.

I very much hope that you will agree that the normal typesetting approach is to be preferred. Speaking for myself, centering commas vertically on the math axis borders on the preposterous...

enter image description here

\documentclass{article}

\usepackage[margin=0pt, paperwidth=3cm, paperheight=0.5cm]{geometry}
\usepackage{xcolor,graphicx}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

% Command to center argument on math axis:
\newcommand\vc[1]{\vcenter{\hbox{$#1$}}} 

%% See https://tex.stackexchange.com/a/414613/5001 for source of the following code
%% Draw a line per font metric (#1 color, #2 vertical position, #3 label)
\newcommand{\drawmetric}[3]{\rlap{%
    \color{#1}\rule[#2]{2.55cm}{0.05pt}%
    \raisebox{#2}{\scalebox{0.3}{%
       \tiny\selectfont\sffamily #3}}%
  }}
\newcommand\drawallmetrics{%
  \drawmetric{red}{0pt}{baseline}%
  \drawmetric{blue}{1ex}{x-height}%
  \drawmetric{red}{\fontcharht\font`X}{cap-height}%
  \drawmetric{cyan}{\the\fontdimen22\textfont2}{math axis}}

\begin{document}

\noindent\rlap{ % 
  $\vc{n}=\vc{0}\ \vc{c}(\vc{C}\mathpunct{\vc{,}}\vc{u}\mathpunct{\vc{,}}\vc{P})$}
  \drawallmetrics{}

\noindent\rlap{ % 
  $n=0\ c(C,u,P)$}
  \drawallmetrics{}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .