# How to left align text in a table with \makecell

This is my code.. I want to left align the statement "number when majority of the nodes.....". Please help

\begin{table}[h!]
\caption{Main Notations}
\label{tab:table1}
\resizebox{9cm}{!}
{
\begin{tabular}{|l|l|p{1cm|}}
\hline
\textbf{Notation} & \textbf{Meaning} \\
\hline
$Pmd$ & local probability of misdetection \\
\hline
$P_{d}$ & local probability of detection \\
\hline
$Pfa$ & probability of false alarm \\
\hline
$Ppu$ & signal \\
\hline
$P_b$ & broadcast \\
\hline
$N_{gd}$ & node 1  \\
\hline
$N_{ln}$ & Total number of node \\
\hline
$h_{gd1}$ & \makecell{h number when majority of the nodes \\ in a topology gives a decision 1' when PU is present} \\
\hline
\end{tabular}
}
\end{table}

• Please post working examples, not just fragments -- and please consider to accept answers to your other questions as well upvoting them ;-) This shows that you appreciate the work of other users here willing to help you!
– user31729
Dec 4, 2015 at 17:55

You just have to write \makecell[l]{…} if you want to left-align (it is vertically and horizontally centred by default).

However, rather than using \resizebox I would suggest one of these two solutions, based on \tabularx and cellspace (for some vertical padding between rows). Makecell is not necessary. Also I loaded caption for a better vertical spacing between caption and table:

\documentclass{article}
\usepackage{array, tabularx, caption, boldline}
\usepackage{graphicx}
\usepackage{cellspace}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}

\begin{document}

\begin{table}[h!]
\caption{Main Notations}
\label{tab:table1}\centering
\begin{tabularx}{9cm}{|Sl|X|}
\hline
\textbf{Notation} & \textbf{Meaning} \\
\hline
$P_{md}$ & local probability of misdetection \\
\hline
$P_{d}$ & local probability of detection \\
\hline
$P_{fa}$ & probability of false alarm \\
\hline
$P_{pu}$ & signal \\
\hline
$P_b$ & broadcast \\
\hline
$N_{gd}$ & node 1 \\
\hline
$N_{ln}$ & Total number of node \\
\hline
$h_{gd1}$ & {h number when majority of the nodes in a topology gives a decision 1' when PU is present} \\
\hline
\end{tabularx}
\end{table}

\begin{table}[h!]
\caption{Main Notations}
\label{tab:table2}\centering
\begin{tabularx}{9cm}{SlV{2}X}
\textbf{Notation} & \textbf{Meaning} \\
\hlineB{1.2}
$P_{md}$ & local probability of misdetection \\
$P_{d}$ & local probability of detection \\
$P_{fa}$ & probability of false alarm \\
$P_{pu}$ & signal \\
$P_b$ & broadcast \\
$N_{gd}$ & node 1 \\
$N_{ln}$ & Total number of node \\
$h_{gd1}$ & {h number when majority of the nodes in a topology gives a decision 1' when PU is present}
\end{tabularx}
\end{table}

\end{document}


• I forgot to explain my edit: I just added a missing backtick.
– Dan
Dec 4, 2015 at 19:57
• @Dan: It's OK with me. I often forget to check may answers, so I'm glad someone else checks. Thanks! Dec 4, 2015 at 20:28
• What exactly in the code makes the text be wrapped inside the table cell? Thanks! Feb 26, 2018 at 13:03
• Using the X column type inside tabularx{some total width}: it is internally a p{length remaining to fill the prescribed total width}. This length is calculated by the package. Feb 26, 2018 at 13:08
• @Bernard Would you kindly help me with a similiar problem I am facing? Aug 18, 2018 at 6:48

I would like to suggest that you go for a table with an "open" look, by getting rid of all vertical rules, most horizontal rules, and using the rule-drawing macros of the booktabs package -- \toprule, \midrule, and \bottomrule -- for the remaining horizontal lines. Rather than using \resizebox to achieve a table width of 9cm, I suggest you use a tabularx environment, whose overall width can be set to the desired width (here: 9cm) directly.

\documentclass{article}

\usepackage{tabularx,booktabs,caption,ragged2e}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}

\begin{document}

\begin{table}[h!]
\centering
\caption{Main Notations}
\label{tab:table1}
\begin{tabularx}{9cm}{@{} lY @{}}
\toprule
\textbf{Notation} & \textbf{Meaning} \\
\midrule
$P_{md}$ & local probability of misdetection \\
$P_{d}$  & local probability of detection \\
$P_{fa}$ & probability of false alarm \\
$P_{pu}$ & signal \\
$P_b$    & broadcast \\
$N_{gd}$ & node 1  \\
$N_{ln}$ & Total number of nodes \\
$h_{gd1}$& $h$ number when majority of nodes in a topology
gives decision 1'' when PU is present \\
\bottomrule
\end{tabularx}
\end{table}

\end{document}


This is copied from the documentation of the makecell package and it worked fine for me. An example for text aligning for all possibilities.

\begin{tabular}{|c|c|}
\hline
Cell text & 28--31\\
\hline
\makecell{Multilined \\ cell text} & 28--31\\
\hline
\makecell[l]{Left aligned \\ cell text} & 37--43\\
\hline
\makecell*[r]{Right aligned \\ cell text} & 37--43\\
\hline
\makecell[b]{Bottom aligned \\ cell text} & 52--58\\
\hline
\makecell*[{{p{3cm}}}]{Cell long text with predefined width} & 52--58\\
\hline
\makecell[{{>{\parindent1em}p{3cm}}}]{Cell long...} & 52--58\\
\hline
\end{tabular}



Today, when is available package tabularray (version 2022A), this table can be written with the following simple code without use of the makecell package:

\documentclass{article}
\usepackage[skip=1ex]{caption}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}

\begin{document}
\begin{table}[ht]
\caption{Main Notations}
\label{tab:table1}\centering
\begin{tblr}{hlines, vlines,
colspec = {Q[l, mode=math]
X[j]},
row{1} = {font=\bfseries, mode=text}
}
Notation    &   Meaning     \\
%
P_{md}      & local probability of misdetection \\
P_{d}       & local probability of detection \\
P_{fa}      & probability of false alarm \\
P_{pu}      & signal \\
N_{gd}      & node 1 \\
N_{ln}      & Total number of node \\
h_{gd1}     & h number when majority of the nodes in a topology gives a decision 1' when PU is present \\
\end{tblr}
\end{table}

or more "open look" (as usual say @Mico):
\begin{table}[ht]
\caption{Main Notations}
\label{tab:table1}\centering
\begin{tblr}{colspec = {Q[l, mode=math]
X[l]},
row{1} = {font=\bfseries, mode=text}
}
\toprule
Notation    &   Meaning     \\
\midrule
P_{md}      & local probability of misdetection \\
P_{d}       & local probability of detection \\
P_{fa}      & probability of false alarm \\
P_{pu}      & signal \\
h_{gd1}     & h number when majority of the nodes in a topology gives a decision 1' when PU is present    \\
`