3

This might be a simple fix, however I can't find a way to do it. (Pic and MWE at the end)

I have a command

\newcommand{\glsbi}[1]{$\left| \quad \begin{aligned}#1\end{aligned}\quad \right|$}

to be able have an equationsystem enclosed in \left| and \right| on the same line.
When defined like this, it works, however it centers the equationsystem vertically with the text before it.

When i change the command to

\newcommand{\glsbt}[1]{$\left| \quad \begin{aligned}[t]#1\end{aligned}\quad \right|$}

it aligns the first equation with the text, however the \left| and \right| go up way too far.

How can i make the \left| and \right| have the same height as in the first command, but have the vertical alignment of the second one?

MWE:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\glsbi}[1]{$\left| \quad \begin{aligned}#1\end{aligned}\quad     \right|$}
\newcommand{\glsbt}[1]{$\left| \quad \begin{aligned}[t]#1\end{aligned}\quad \right|$}

\begin{document}
Works as intended: \glsbi{x &= y \\ x &= 2y + 3}\\[1cm]

Works not as intended: \glsbt{x &= y \\ x &= 2y + 3}
\end{document}

Picture:

1
  • \left and \right equalize the delimiters so there's as much above the baseline as below (with a small correction due to the formula axis).
    – egreg
    Oct 4, 2018 at 17:46

2 Answers 2

2

A little bit of box manipulation:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\glsbi}[1]{$\left| \quad \begin{aligned}#1\end{aligned} \quad \right|$}

\makeatletter
\newcommand{\glsbt}[1]{%
  \sbox\z@{$\begin{aligned}#1\end{aligned}$}%
  \sbox\tw@{$\begin{aligned}[t]#1\end{aligned}$}%
  \raisebox{\dimexpr\dp\z@-\dp\tw@\relax}{$\left| \quad \copy\z@ \quad \right|$}%
}
\makeatother

\begin{document}
Works as intended: \glsbi{x &= y \\ x &= 2y + 3}\\[1cm]

Works also as intended: \glsbt{x &= y \\ x &= 2y + 3}
\end{document}

vertical

3
  • 2
    Better \sbox\z@{<contents>} than \setbox\z@=\hbox{<contents>}. You were slightly faster than me. :-) But I used \dimexpr\ht\tw@-\ht\z@.
    – egreg
    Oct 4, 2018 at 18:07
  • @egreg Ah yes, the better LaTeX syntax which respects the color. Oct 4, 2018 at 18:10
  • Thanks so much! Works like a charm! @egreg: Thanks as well. I changed it to sbox, as I understand its a safer to use. I'm very bad still at that level of manipulation.
    – Shakaja
    Oct 4, 2018 at 18:16
2

Just to present a different strategy than in Ruixi Zhang's fine answer, you can use delarray:

\documentclass{article}
\usepackage{amsmath}
\usepackage{delarray}

\newcommand{\glsbi}[1]{$\left|\quad\begin{aligned}#1\end{aligned}\quad\right|$}
\newcommand{\glsbt}[1]{%
  $\begin{array}[t]|{@{\quad}c@{\quad}}|
   \begin{aligned}[t]#1\end{aligned}
  \end{array}$%
}

\begin{document}

Works as intended: \glsbi{x &= y \\ x &= 2y + 3}

\bigskip

Works as intended: \glsbt{x &= y \\ x &= 2y + 3 }

\end{document}

enter image description here

2
  • I also tried to get this solution to work, but I must have a conflict with some other package i use, with this version it just leaves blank space. In the MWE it works like a charm thoo!
    – Shakaja
    Oct 4, 2018 at 18:53
  • Found it, the conflict is with the package colortbl
    – Shakaja
    Oct 4, 2018 at 19:04

You must log in to answer this question.

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