2

I often want to write formulas in one column and text in another column. This helps me create nice cheat sheets where everything is aligned and clean, but I'm having trouble getting consistent results. Wether I use tabular, tabularx, minipages or arrays, there is always some problem (ugly table outputs, some cells won't have aligned content or the generated table is good but can't easily be moved where I want it to, etc.).

Right now, I am trying to use the array environment:

\documentclass{article}

\usepackage{amsmath}

    \begin{document}
        \begin{equation*}
            \begin{array}{|l|l|}
                \hline
                \displaystyle\int x\;dx & \text{\textbf{This} is correctly left justified}\\
                \displaystyle\int \dfrac{1}{x}\;dx & \text{\textbf{This} is also correctly left justified}\\
                \displaystyle\int \dfrac{\text{degree $m$ polynomial}}{\text{degree $n$ polynomial}}\; dx &
                \begin{array}{l}
                    \text{If $m\geq n$: use this technique}\\
                    \text{If $m<n$: use that other technique}
                \end{array}\\
                \displaystyle\int f(x)\;dx & \text{The above two If's are not left justified with the two \textbf{This}'s}\\
                \hline
            \end{array}
        \end{equation*}
    \end{document}

Which outputs this:

enter image description here

The Problem

As you can see, on third row/2nd column of the array, I used anoter array statement to write two lines within the same row, but they are a bit offset to the right. I'm thinking there's an invisible blank vertical line (where an actual line would be if I had written {|l|} in the nest array's columns instead of just {l}). Is there any way to get rid of that 'indent' (if we can call it that)?

Additional info

In case someone asks, here is a similar attempt I did using tabularx (where I use \newline instead of a nested array):

\documentclass{article}

\usepackage{amsmath}
\usepackage{tabularx}

\begin{document}
    \begin{table}[h]
        \begin{tabularx}{\textwidth}{|lX|}
            \hline
            $\displaystyle\int x\;dx$ & \textbf{This} is correctly left justified\\
            $\displaystyle\int \dfrac{1}{x}\;dx$ & \textbf{This} is also correctly left justified\\
            $\displaystyle\int \dfrac{\text{degree $m$ polynomial}}{\text{degree $n$ polynomial}}\;dx$ & 
                \text{If $m\geq n$: use this technique}\newline
                \text{If $m<n$: use that other technique}\\
            $\displaystyle\int f(x)\;dx$ & \text{The above two If's are not aligned to the top of the row}\\
            \hline
        \end{tabularx}
    \end{table}
\end{document}

Which outputs this:

enter image description here

As you can see, now the If's are justified but not aligned with the top of the integral on the left. (Don't worry about the line overflowing out of the table for this example).

I've been playing this game of whack-a-mole of trying to find the right environment for the job for a while now and would appreciate some help!

Thanks in advance.

1
  • For the inner array, you could use \begin{array}{@{}l@{}}. The @{} suppresses the extra space. Commented Nov 12, 2022 at 9:09

2 Answers 2

3

Probably you like to have the following table:

enter image description here

By use of the tabularray package is easy to obtain it without nesting of tables. Also table code is shorter and clearer:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}

\begin{document}
\begin{center}
    \begin{tblr}{hline{1,Z}=solid, vlines,
                 colspec={Q[l, mode=dmath] X[l,m]},
                 rowsep=5pt
                 }
\int x\;dx              & \textbf{This} is correctly left justified         \\
\int \dfrac{1}{x}\;dx   & \textbf{This} is also correctly left justified    \\
\int \dfrac{\text{degree $m$ polynomial}}
           {\text{degree $n$ polynomial}}\;dx 
                        & { If $m\geq n$: use this technique\\
                            If $m<n$: use that other technique}             \\
\int f(x)\;dx           & The above two "If's" are aligned  to the left and 
                          vertical center of the row                       \\
    \end{tblr}
\end{center}
\end{document}
1
  • Thank you, this not only fixes the issue, but also makes it easy to use multilines in a single row and spaces out each lines (rowsep) making the table look clearner.
    – orion2112
    Commented Nov 12, 2022 at 3:54
2

Here's how I would create the table, while still using a tabularx environment. I use a macro called \tint ("tall int") instead of \int to keep the integral symbol in the first row from touching the top line and the integral symbol in the final row touching the bottom line. Observe that I've gotten rid of quite a few of your \text wrappers.

enter image description here

\documentclass{article} 

\usepackage{amsmath}  % for "\text" macro
\usepackage{tabularx} % "tabularx" environment and "X" column type
\newcolumntype{L}{>{$\displaystyle}l<{$}} % automatic display-style math mode
\newcolumntype{Y}{>{\raggedright\arraybackslash}X} % left-aligned, not fully justified
\newcommand\tint{\int^{\mathstrut}_{\mathstrut}} % "tall" integral

\begin{document}

\begin{center} % no need for a "table" environment, right?
\renewcommand\tabularxcolumn[1]{m{#1}} % vertical centering
\begin{tabularx}{\textwidth}{|LY|}
\hline

\tint x\,dx 
   & \textbf{This} is correctly left justified \\
   
\tint\frac{1}{x}\,dx 
   & \textbf{This} is also correctly left justified \\
   
\tint \frac{\text{degree $m$ polynomial}}{\text{degree $n$ polynomial}}\,dx 
   & If $m\geq n$: use this technique \newline
     If $m<n$: use that other technique \\
             
\tint f(x)\,dx 
   & The above two If's are not aligned to the top of the row \\

\hline
\end{tabularx}
\end{center}

\end{document}

You must log in to answer this question.

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