2

I have the following table:

\documentclass[Journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
%\arrayrulecolor{mycolor}
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{4pt}    
\usepackage{tikz}
\def\checkmark{\tikz\fill[scale=0.4](0,.35) -- (.25,0) -- (1,.7) -- (.25,.15) -- cycle;}
\usepackage{tabularx,ragged2e}
\usepackage{caption}
\usepackage{booktabs}
\usepackage{fancyhdr} % for header footer

\begin{document}
\begin{table*}
    \centering
    \caption{Some caption}
    \label{table:tab1}
    \begin{tabular}{rcccccc}
        \toprule
        \textbf{Column 1} & \multicolumn{1}{c}{\textbf{Column 2}} & \multicolumn{1}{c}{\textbf{Column 3}} & \multicolumn{1}{c}{\textbf{Column 4}} & \multicolumn{1}{c}{\textbf{ Column 5}} & \multicolumn{1}{c}{\textbf{ Column 6}} & \multicolumn{1}{c}{\textbf{ Column 7}} \\
        \midrule
        ABC et al [21] &  &  &\checkmark&& \checkmark& \shortstack{Some text goes here\\and some here}\\ 
        \midrule
        XYZ et al [23] &  &  \checkmark&    \checkmark& & & \shortstack{Similarly some text here\\and some here}\\

        \bottomrule
    \end{tabular}%
    \label{tab:dvar}%
\end{table*}%

\end{document}

This code results in the following table: enter image description here

I want the second line of column 7's first cell "and some here" to start just below "Some text goes here". And the same for all cells of column 7. In simple words I want both the rows in each cell of column 7 to be left aligned. If you notice in the current scenario the first line is left aligned but the second isn't. How do I do it. Appreciated.

4
  • what about using l in last column like: \begin{tabular}{rcccccl}?
    – koleygr
    Commented Apr 6, 2018 at 9:46
  • works just for the first line
    – Saad
    Commented Apr 6, 2018 at 9:47
  • 1
    What about \shortstack[l]{...}? (There is a lowercase L as an optional argument... And possibly previous comment has to used too)..
    – koleygr
    Commented Apr 6, 2018 at 9:50
  • post it as an answer so I can accept it
    – Saad
    Commented Apr 6, 2018 at 9:51

2 Answers 2

1

I found here: https://tex.stackexchange.com/a/42860/120578
that \shortstack has an optional argument about the alignment of the contained text.

A left alignment in the column type of the last row is a must too, because if not used, only the current text of every \shortstack will be aligned and no alignment will be generated between different cells.

So, just use something like this:

\documentclass[landscape]{article}
\usepackage{tikz}
\def\checkmark{\tikz\fill[scale=0.4](0,.35) -- (.25,0) -- (1,.7) -- (.25,.15) -- cycle;} 

\begin{document}
\noindent\begin{tabular}{rcccccl}\hline
        \textbf{Column 1} & \multicolumn{1}{c}{\textbf{Column 2}} & \multicolumn{1}{c}{\textbf{Column 3}} & \multicolumn{1}{c}{\textbf{Column 4}} & \multicolumn{1}{c}{\textbf{ Column 5}} & \multicolumn{1}{c}{\textbf{ Column 6}} & \multicolumn{1}{c}{\textbf{ Column 7}} \\\hline
        ABC et al [21] &  &  &\checkmark&& \checkmark& \shortstack[l]{Some text goes here\\and some here}\\ \hline
        XYZ et al [23] &  &  \checkmark&    \checkmark& & & \shortstack[l]{Similarly some text here\\and some here}\\\hline
    \end{tabular}%
\end{document}

(\checkmark is from here: https://tex.stackexchange.com/a/132790/120578)

enter image description here

PS: Thanks for introducing \shortstack command to me`

1
  • That helped. And I am glad I helped too.
    – Saad
    Commented Apr 6, 2018 at 10:10
3

You also can use the makecell package, which lets you have line breaks in standard columns, and define a common formatting of the arguments of \makecell and \thead.

Another, unrelated remark: I don't think a hammersledge like TikZ should be used for checkmarks, as there are some symbols font packages which already define them. I use two of them in the following code:

\documentclass[Journal]{IEEEtran}
\usepackage[utf8]{inputenc}
\usepackage[table]{xcolor}
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{4pt}
\usepackage{tikz}
\def\checkmark{\tikz\fill[scale=0.4](0,.35) -- (.25,0) -- (1,.7) -- (.25,.15) -- cycle;}
\usepackage{tabularx,ragged2e}
\usepackage{caption, makecell}
\usepackage{booktabs}
\usepackage{fancyhdr} % for header footer
\usepackage{bbding, pifont}

\begin{document}

\begin{table*}
    \centering\renewcommand{\cellalign}{bl}
\renewcommand{\theadfont}{\normalsize\bfseries}
    \caption{Some caption}
    \label{table:tab1}
    \begin{tabular}{@{}rcccccl@{}}
        \toprule
        \thead{Column 1} & \thead{Column 2} & \thead{Column 3} & \thead{Column 4} & \thead{ Column 5} & \thead{ Column 6} & \thead{Column 7} \\
        \midrule
        ABC et al [21] & & &\checkmark&& \checkmark& \makecell{Some text goes here\\and some here}\\
        \midrule
        XYZ et al [23] & & \ding{51}& \Checkmark& & & \makecell{Similarly some text here\\and some here}\\

        \bottomrule
    \end{tabular}%
    \label{tab:dvar}%
    \end{table*}%

    \end{document} 

enter image description here

1
  • Another option is to use \makecell[l]{Some text goes here\\and some here} instead of redefining \cellalign
    – Trevor
    Commented Oct 21, 2022 at 23:45

You must log in to answer this question.

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