Text FormattingSame Height for Undersets and Subscripts

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
olegkomarov
Posts: 10
Joined: Tue Jul 26, 2011 4:24 am

Same Height for Undersets and Subscripts

Post by olegkomarov »

This example entails multiple questions:

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage[itGreek,upgreek]{pxgreeks}  % Upright lower (for vector notation) and slanted upper greeks 

% New commands
\newcommand{\bbeta}[1]{\boldsymbol\beta_{\scriptscriptstyle #1}}
\newcommand{\undset}[2]{\underset{\scriptscriptstyle #1}{#2}}
\newcommand{\by}[1]{\mathbf y_{\scriptscriptstyle #1}}
\newcommand{\bx}[1]{\mathbf x_{\scriptscriptstyle #1}}
\newcommand{\bF}{\mathbf F}

\begin{document}
    \begin{equation}
        \begin{array}{ccl}
            \undset{n\times1}{\by{t}} & = & \undset{k \times k}{\bx{t}} \, \undset{k \times 1}{\bbeta{t}} \\[10pt]
            \undset{k\times1}{\bbeta{t+1}} & = & \undset{k\times k}{\bF(\bx{t})} \, \undset{k \times 1}{\bbeta{t}}
        \end{array}
    \end{equation}
\end{document}
which compiles the following
equal-underset-height.png
equal-underset-height.png (8.58 KiB) Viewed 6357 times
Now, how can I:
  • position the undersets at the same height?
  • position the subscripts at the same height?
  • is there a better way to define the size of the subscript to be by default \scriptscriptstyle
Also, I really appreciate general suggestions to achieve more elegant code.

Thanks in advance,

Best
Oleg

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Same Height for Undersets and Subscripts

Post by localghost »

The key is the definition of your new commands, exactly two of them come in question.

Code: Select all

\newcommand{\bbeta}[1]{\boldsymbol\beta_{\scriptscriptstyle #1}}
\newcommand{\undset}[2]{\underset{\scriptscriptstyle #1}{#2}}
The following modifications are necesssary to get the desire result.
  1. Put an additional pair of curly braces behind the \beta to hide its descender from the following subscript.
  2. Add a \strut in the second argument of the new command to give them all the same depth.
These suggestions translated to your code make the concerned lines look like this.

Code: Select all

\newcommand{\bbeta}[1]{\boldsymbol\beta{}_{\scriptscriptstyle #1}}
\newcommand{\undset}[2]{\underset{\scriptscriptstyle #1}{#2\strut}}
If you now embed these modifications in your sample document, you will get what you are after.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}
\usepackage[itGreek,upgreek]{pxgreeks}   % Upright lower (for vector notation) and slanted upper greeks

% New commands
\newcommand{\bbeta}[1]{\boldsymbol\beta{}_{\scriptscriptstyle #1}}
\newcommand{\undset}[2]{\underset{\scriptscriptstyle #1}{#2\strut}}
\newcommand{\by}[1]{\mathbf{y}_{\scriptscriptstyle #1}}
\newcommand{\bx}[1]{\mathbf{x}_{\scriptscriptstyle #1}}
\newcommand{\bF}{\mathbf{F}}

\begin{document}
  \begin{equation}
    \begin{aligned}
      \undset{n\times 1}{\by{t}} &= \undset{k\times k}{\bx{t}}\,\undset{k\times 1}{\bbeta{t}} \\
      \undset{k\times 1}{\bbeta{t+1}} &= \undset{k\times k}{\bF(\bx{t})}\,\undset{k\times 1}{\bbeta{t}}
    \end{aligned}
  \end{equation}
\end{document}
The resulting output is attached.

For correct alignment of the equations the »aligned« environment from amsmath (here loaded by mathtools) is the better way.

The size of subscripts might be done by the \DeclareMathSizes command. But since you defined some new commands as shortcuts, you can embed font size commands directly so that it is not necessarily the better choice here.
Attachments
The rendered output obtained by the proposed modifications.
The rendered output obtained by the proposed modifications.
tmp.png (11.35 KiB) Viewed 6357 times
olegkomarov
Posts: 10
Joined: Tue Jul 26, 2011 4:24 am

Same Height for Undersets and Subscripts

Post by olegkomarov »

Thanks localghost!
I actually found other similar unanswered questions and I think your contribution here will be appreaciated by many.

EDIT
Subsequently, I was confronted with the fact that subscripts are lowered when superscripts appear (I use a lot the transpose). To keep subscripts at the same level I load subdepth which also takes care of my second question in the original post. Thus, I don't need additional curly braces after the letter/symbol anymore.
Post Reply