3

I want a Table that looks like this, enter image description here

The code that I use in Overleaf is this below,

\documentclass{article}

\begin{document}
    \begin{table}[h!] 
    \centering
    \begin{tabular}{|c|c|c|c|c|}
    \hline
    \textbf{Metrices} & \textbf{UTL} & \textbf{BEC} & \textbf{CTH} & \textbf{IWW} \\ 
    \hline
    \textbf{Ge Fraction (in D4R)} & 12 & 24 & 16 & 4 \\ 
    \hline
    \textbf{Total CN (Ge-Ge)} & 28 & 20 & 9 & 7 \\ 
    \hline
    \hspace{0.6cm} \newline \textbf{D4R,} & 12, & 24, & 16,  &  4, \\ 
    \textbf{Occu Freq} \newline \textbf{Adj,} & 15, & 43, & 5, & 10, \\ \hspace{0.6cm}
    \newline \textbf{  Frw} & 20 & 20 & 8 & 7 \\ 
    \hline
    \end{tabular}
    \end{table}
\end{document}

The result of this looks like this, enter image description here

Please suggest how to align the D4R, Adj, and Frw in the same way as intended. Thanks.

2
  • 1
    You could split your first column in two and use \multicolumn for the first three rows. By the way, why are you using \newline in several places in the big cell? Commented Jun 6, 2024 at 7:42
  • You could also use a {tabular} for that cell. Please also have a look at the booktabs pacakge. Commented Jun 6, 2024 at 7:54

3 Answers 3

6

Although not the most elegant solution, I used \multicolumn.

\documentclass{article}

\begin{document}

\begin{table}[h] 
    \centering
    \begin{tabular}{|cl|c|c|c|c|} \hline
        \multicolumn{2}{|c|}{\textbf{Metrices}} & \textbf{UTL} & \textbf{BEC} & \textbf{CTH} & \textbf{IWW} \\ \hline
        \multicolumn{2}{|c|}{\textbf{Ge Fraction (in D4R)}} & 12 & 24 & 16 & 4 \\ \hline
        \multicolumn{2}{|c|}{\textbf{Total CN (Ge-Ge)}} & 28 & 20 & 9 & 7 \\ \hline
        & \textbf{D4R,} & 12, & 24, & 16,  &  4, \\ 
        \textbf{Occu Freq} & \textbf{Adj,} & 15, & 43, & 5, & 10, \\
        & \textbf{Frw} & 20 & 20 & 8 & 7 \\ \hline
    \end{tabular}
\end{table}

\end{document}

enter image description here

4

You can use a “phantom”. I measure the text and locally define a command that leaves the precise amount of space.

However, I'd prefer the style of the second table; with more space available you can avoid ugly abbreviations such as “Occu Freq” (I didn't dare to expand it, though).

\documentclass{article}
\usepackage{booktabs}% for the second realization

\newlength{\indranillength} % a scratch length for your needs

\begin{document}

\begin{table}[htp]
\centering

\settowidth{\indranillength}{\textbf{Occu Freq }}
\newcommand{\OF}{\hspace{\indranillength}}

\begin{tabular}{|l|c|c|c|c|}\hline
\textbf{Metrics} & \textbf{UTL} & \textbf{BEC} & \textbf{CTH} & \textbf{IWW} \\ \hline
\textbf{Ge Fraction (in D4R)} & 12 & 24 & 16 &  4 \\ \hline
\textbf{Total CN (Ge-Ge)}     & 28 & 20 &  9 &  7 \\ \hline
\OF       \textbf{D4R}        & 12 & 24 & 16 &  4 \\ 
\textbf{Occu Freq Adj}        & 15 & 43 &  5 & 10 \\
\OF       \textbf{Frw}        & 20 & 20 &  8 &  7 \\ \hline
\end{tabular}

\caption{A caged table, difficult to read}
\end{table}

\begin{table}[htp]
\centering

\begin{tabular}{@{}lcccc@{}}
\toprule
Metrics & UTL & BEC & CTH & IWW \\
\midrule
Ge Fraction (in D4R) & 12 & 24 & 16 &  4 \\
Total CN (Ge-Ge)     & 28 & 20 &  9 &  7 \\
\midrule
\multicolumn{5}{@{}l@{}}{\itshape Occu Freq} \\
D4R                  & 12 & 24 & 16 &  4 \\ 
Adj                  & 15 & 43 &  5 & 10 \\
Frw                  & 20 & 20 &  8 &  7 \\
\bottomrule
\end{tabular}

\caption{An open look table, easier to read}
\end{table}

\end{document}

I removed the commas, which I think aren't really useful.

enter image description here

2

With {NiceTabular} of nicematrix. However, I recommend in the style and spirit of booktabs (seed egreg's answer).

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\renewcommand{\arraystretch}{1.2}

\begin{NiceTabular}{|l|c|c|c|c|}[,hlines={1,2,3,4,7},ampersand-in-blocks]
Metrics & UTL & BEC & CTH & IWW \\
Ge fraction (in D4R) & 12 & 24 & 16 & 4 \\
Total CN (Ge-Ge) & 28 & 20 & 9 & 7 \\
\Block[l]{}{&D4R} & 12 & 24 & 16 & 4 \\
\Block[l]{}{Occu Freq&Adj} & 25 & 43 & 5 & 10 \\
\Block[l]{}{&Frw} & 20 & 20 & 8 & 7 \\
\end{NiceTabular}

\end{document}

Output of the above code

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.