# How to align braces and \mid in a set in order to get the same height

## Main question

How to align braces and \mid in a set in order to get the same height?

## Code:

My following code

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

$G_1=\left\{ \begin{pmatrix} 1 \\ -2 \\ 3 \\ 4 \end{pmatrix} + \lambda \begin{pmatrix} -2 \\ 3 \\ 4 \\ -5 \end{pmatrix} \mid \lambda \in \mathbb{R}\right\}$
\end{document}


compiles to:

Does this is a better visualization than:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}

$G_1=\{ \begin{pmatrix} 1 \\ -2 \\ 3 \\ 4 \end{pmatrix} + \lambda \begin{pmatrix} -2 \\ 3 \\ 4 \\ -5 \end{pmatrix} \mid \lambda \in \mathbb{R}\}$
\end{document}


which compiles to:

?

## Other questions

1. How do I align the negative numbers of the vectors correctly?
2. How do I manage to change the relational symbol \mid to a bigger one that fits the height of the vectors/braces?
3. Which is the best way to visualize G_1 if none of the visualizations above are good enough?
• what do you mean by "formal" and "fancy" here? (I know what the words mean, but I can not guess what you mean in this context) – David Carlisle Apr 16 '19 at 18:49
• \middle\vert should grow the vertical bar in a \left...\right construct. – Steven B. Segletes Apr 16 '19 at 18:50
• Sry for the misleading words. I wanted to express, that the braces, \mid and all vectors have the same height. Furthermore, it would be good, if the negative numbers are aligned correctly – Doesbaddel Apr 16 '19 at 18:52
• @DavidCarlisle alright, I will change it. – Doesbaddel Apr 16 '19 at 18:59

I suggest using the pmatrix*[r] environment, from mathtools, in a medium-sized version thanks to the medsize environment from nccmath. Also, I used a \set command based on \DeclarePairedDelimiterX (again from mathtools), which uses two arguments, separated by a semi-colon:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amssymb}
\usepackage{mathtools, nccmath}

\newenvironment{pmmatrix*}[1][c]{\medsize\begin{pmatrix*}[#1]}{ \end{pmatrix*}\endmedsize}
\usepackage{xparse}
\DeclarePairedDelimiterX{\set}[1]\{\}{\setargs{#1}}
\NewDocumentCommand{\setargs}{>{\SplitArgument{1}{;}}m}
{\setargsaux#1}
\NewDocumentCommand{\setargsaux}{mm}
{\IfNoValueTF{#2}{#1}{\nonscript\,#1\nonscript\;\delimsize\vert\nonscript\:\allowbreak\mathopen{}#2\nonscript\,}}

\begin{document}

$\set*{\begin{pmmatrix*}[r]1\\ -2 \\ 3 \\ 4 \end{pmmatrix*} + \lambda\begin{pmmatrix*}[r]-2 \\ 3 \\ 4 \\ -5 \end{pmmatrix*}; \lambda\in\mathbf{R}}$

\end{document}


• Thank you for a different approach of the problem! – Doesbaddel Apr 16 '19 at 20:25
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tabstackengine}
\begin{document}

$G_1=\left\{ \parenVectorstack[r]{ 1 \\ -2 \\ 3 \\ 4 } + \lambda \parenVectorstack[r]{ -2 \\ 3 \\ 4 \\ -5 } \middle\vert\, \lambda \in \mathbb{R}\right\}$
\end{document}


• Thank you! This is what I actually was looking for but one last question: How can you change the spacing of the vertical line so that it has the same space to the vector and the lambda? – Doesbaddel Apr 16 '19 at 18:59
• @Doesbaddel Either add \! before \middle\vert or add \, after \middle\vert. I have edited my answer to reflect this. – Steven B. Segletes Apr 16 '19 at 19:00
• @Doesbaddel Note: you can also change the row spacing (baselineskip) prior to building the vector stacks, with \setstackgap{L}{14pt} (currently \baselineskip = 12pt). – Steven B. Segletes Apr 16 '19 at 19:05

Using spalign package you can obtain same result of the best answers of @Bernard and @Steven B. Segletes. The code is not very long.

\documentclass[12pt]{article}
\usepackage{spalign}
\usepackage{amssymb}

\begin{document}

G_1=\left\{ \spalignvector[r]{1 -2 3 4}+\lambda\spalignvector[r]{1 -2 3 4} \middle\vert\ \lambda\in \mathbb{R}\right\}
\end{document}