0

I'm having two independent problems while creating a table.

First, how can I center a column's top row (column's name) but keep the text of the following rows left justified?

My second problem is when I'm trying to fill one cell with the next term: $\sqrt{\frac{\rho C_{p}r_{h}^{2}/K}{1/\omega}}$ I want the numerator and denominator to have more vertical space for better visualization.

Additionally, if there is a nicer way to represents the fractions in the numerator and denominator, that would also be helpful. I am copying all the math codes from LyX, which gave me the function \nicefrac{}{}, but apparently it's not included in my packages.

Au101
  • 10,278
dfel
  • 11

2 Answers2

1

Another solution, using \addlinespace where it's useful to give some vertical padding to cells.

Additionally, I loaded the makecell package: its \head and `\makecell commands allow line breaks inside them, their contents is vertically and horizontally centred by default, and can have a common formatting. I had toi reduce the size of the table columns, as they overflowed into the margin:

\documentclass[12pt]{article}

\usepackage{nicefrac, array, booktabs, makecell, showframe} %
\renewcommand\theadfont{\normalsize\itshape}
\renewcommand\ShowFrameLinethickness{0.3pt}

\begin{document}

{\centering\begin{tabular}{@{}p{1.65in}p{1.65in}p{1.65in}@{}}
  \toprule
  \thead{Centered header} & % \multicolumn lets you locally
  \thead{Centered header} & % override column alignment
  \thead{Centered header} \tabularnewline
  \midrule
  \addlinespace[2ex]
  %
  Left-aligned & $√{\nicefrac{ρC_{p}r_{h}^{2}/K}{1/ω}}$ & Left-aligned \tabularnewline
  \addlinespace[1ex]
  \bottomrule
  \end{tabular}}

\end{document} 

Bernard
  • 271,350
0

enter image description hereThis code addresses point 1 and 2:

\documentclass[12pt]{article}

\usepackage{nicefrac, array, booktabs}  % nicefrac adds \nicefrac command
                                        % booktabs makes prettier tables
\usepackage[margin=1in]{geometry}

\begin{document}
\renewcommand{\arraystretch}{1.5}       % make table a bit airier
\begin{tabular}{@{}p{2in}p{2in}p{2in}@{}}
\toprule
\multicolumn{1}{c}{Centered header} &   % \multicolumn lets you locally 
\multicolumn{1}{c}{Centered header} &   % override column alignment
\multicolumn{1}{c}{Centered header} \tabularnewline
\midrule
%
Left-aligned & $\sqrt{\nicefrac{\rho C_{p}r_{h}^{2}/K}{1/\omega}}$ & Left-aligned \tabularnewline
\bottomrule
\end{tabular}

\end{document}

IMO you don't need both \nicefrac and additional vertical whitespace in your fraction. However, if you want to investigate how to do it, maybe this is a good place to start:

Strutting around: What's the difference between \strut, \mathstrut and \vphantom?