12

I try to align the letters b,d,t exactly vertically stacked. But the \neg symbol has unkown width. What is it and how to find it out in general? Numerous spacings exist, but whats the exact one?

\documentclass{article}
\usepackage{amsmath, booktabs}

\begin{document}
\begin{tabular}{@{}ll@{}}
\toprule
combination         & example \\ \midrule
$(b,\ \ \ d,\ \ \ t)$           &         \\
$(b,\ \ \ d,\neg t)$      &         \\
$(b,\neg d,\ \ t)$      & double auction \\
$(b,\neg d,\neg t)$ &         \\ \bottomrule
\end{tabular}
\end{document}

pic

20

\hphantom{\neg} will insert a horizontal space exactly the same as \neg

\documentclass{article}
\usepackage{amsmath, booktabs}

\begin{document}
\begin{tabular}{@{}ll@{}}
\toprule
combination         & example \\ \midrule
$(b,\hphantom{\neg} d,\hphantom{\neg} t)$           &         \\
$(b,\hphantom{\neg} d,\neg t)$      &         \\
$(b,\neg d,\hphantom{\neg} t)$      & double auction \\
$(b,\neg d,\neg t)$ &         \\ \bottomrule
\end{tabular}
\end{document}
  • 1
    this has the advantage of no def or newcommands. nice – qrtLs May 1 '19 at 13:14
  • 2
    @ItsmeJulian There are more commands like this. In case you need the vertical space of something there is \vphantom{...} and for both vertical and horizontal space there is \phantom{...}. – user187977 May 1 '19 at 13:26
5

This makes all components the same width, specified here as 2.1ex, plus an added inter-column gap of \,\,.

This allows some flexibility if the array content changes and allows for the presence of \neg in the first column.

\documentclass{article}
\usepackage{amsmath, booktabs}
\newcommand\cw{2.1ex}
\def\z(#1,#2,#3){%
  (\makebox[\cw][r]{$#1$},\,\,\makebox[\cw][r]{$#2$},\,\,\makebox[\cw][r]{$#3$})}
\begin{document}
\begin{tabular}{@{}ll@{}}
\toprule
combination         & example \\ \midrule
$\z(b,d,t)$           &         \\
$\z(b,d,\neg t)$      &         \\
$\z(b,\neg d,t)$      & double auction \\
$\z(b,\neg d,\neg t)$ &         \\ \bottomrule
\end{tabular}
\end{document}

enter image description here

But if you wanted the output tailored to this particular set of arrays, then

\documentclass{article}
\usepackage{amsmath, booktabs}
\setbox0=\hbox{$b$}
\edef\cwA{\the\wd0}
\setbox0=\hbox{$\neg d$}
\edef\cwB{\the\wd0}
\setbox0=\hbox{$\neg t$}
\edef\cwC{\the\wd0}
\def\z(#1,#2,#3){%
  (\makebox[\cwA][r]{$#1$},\,\,\makebox[\cwB][r]{$#2$},\,\,\makebox[\cwC][r]{$#3$})}
\begin{document}
\begin{tabular}{@{}ll@{}}
\toprule
combination         & example \\ \midrule
$\z(b,d,t)$           &         \\
$\z(b,d,\neg t)$      &         \\
$\z(b,\neg d,t)$      & double auction \\
$\z(b,\neg d,\neg t)$ &         \\ \bottomrule
\end{tabular}
\end{document}

enter image description here

5

Another way uses the \eqparbox package, which defines a system of tags for the standard box commands: all boxes sharing the same tag have as width of the natural width of the widest box in the series.

\documentclass{article}
\usepackage{amsmath, booktabs}
\usepackage{eqparbox}
\newcommand{\eqmathbox}[2][T]{\eqmakebox[#1][r]{$#2$}}

\begin{document}

\begin{tabular}{@{}ll@{}}

\toprule
combination & example \\ \midrule
$(b, \eqmathbox[D]{d},\eqmathbox{ t})$ & \\
$(b,\eqmathbox[D]{d}, \eqmathbox{t})$ & \\
$(b,\eqmathbox[D]{\neg d}, \eqmathbox{t})$ & double auction \\
$(b,\eqmathbox[D]{\neg d},\eqmathbox{\neg t})$ & \\ \bottomrule
\end{tabular}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.