1

We can use

\renewcommand{\arraystretch}{2}

to increase the height of rows. The text, however, is just in the center.

How can we simply put it on the top-left, as in the second and third columns in the picture?

Note: this is drawn by Tikz. I want it with tabular if possible.

3 columns

2 Answers 2

3

This is simple to achieve by use of the tabularray package. It define belowskip option for setting vertical distance below cells contents:

\documentclass{article}
\usepackage{tabularray}

\begin{document}

\begin{tblr}{hlines, vlines,
              colspec = {*{3}{c}},
             belowsep = 12mm,
             }
a) T.Insert(8) & b) T.Insert(12) & c) T.Insert(10)  \\
\end{tblr}

\end{document}

enter image description here

Addendum: Let me add top left alignment of cell contents. I is visible, if cell's width is bigger than that this text width. Assuming that all cells have the same width and that table width is equal to \textwidth, than the cells specifier should be X[l]}. That new positioning of text in cell is better visible, let add package geometry for wider text area:

\documentclass{article}
\usepackage{geometry}
\usepackage{tabularray}

\begin{document}

\begin{tblr}{hlines, vlines,
              colspec = {*{3}{X[l]}},
             belowsep = 12mm,
             }
a) T.Insert(8) & b) T.Insert(12) & c) T.Insert(10)  \\
\end{tblr}

\end{document}

enter image description here

6
  • Nice, Today it hit 2500 views, and I've corrected some typos on the question and got a different approach.
    – kelalaka
    Jun 14 at 17:08
  • @kelalaka, I didn't see your question before. this solution is possible recent two years or so. Anyway, answer is not only "nice" but "excellent" :-) [just a joke, nice is just fine]
    – Zarko
    Jun 14 at 18:16
  • :) thanks for the information. I'll look at the package. I was building an exam-style for my needs.
    – kelalaka
    Jun 14 at 18:19
  • 1
    @kelalaka, recent version of package is 2022B. It was published Jun 1, 2022. It is based on LaTeX3 project. To my opinion is very powerful, but with a little bit different syntax from "classic" packages for tables. Syntax is easy to learn.
    – Zarko
    Jun 14 at 18:22
  • 1
    @kelalaka, see addendum to answer. You only need to change column specifier (from`` to X[l]
    – Zarko
    Jun 14 at 19:33
2

The easiest solution is to modify the contents of the cell, The first solutions added a "strut" extending downward, while the second shows a more general approach using \raisebox.

\documentclass{article}
\begin{document}
\begin{tabular}{|c|c|c|}
\hline
\rule[-2\normalbaselineskip]{0pt}{3\normalbaselineskip}% strut
a) T.Insert(8) & b) T.Insert(12) & c) T.Insert(10) \\
\hline
\end{tabular}

\bigskip
\begin{tabular}{|c|c|c|}
\hline
\raisebox{\normalbaselineskip}{a) T.Insert(8)} & 
\raisebox{0pt}[2\normalbaselineskip][1.6\normalbaselineskip]{b) T.Insert(12)} &% baseline here
\raisebox{-\normalbaselineskip}{c) T.Insert(10)} \\
\hline
\end{tabular}
\end{document}

tabulars

2
  • It doesn't look like a real solution. It looks like a workaround. Could we just say that in normal circumstances there is no easy way to align cell content top-left? You always have to use typographic "tricks". Isn't it that way?
    – buhtz
    Jul 10, 2016 at 7:17
  • @bulitz - All of LaTeX is based on typographical tricks. There is strut automatically added whose size is determined by \arraystretch. If you want to modify the source code you could have a real solution. But in the end, both would be doing the exact same thing. Jul 10, 2016 at 15:48

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.