3

Here is my issue,

I'm trying to fix the width of the second column only (meaning reducing then ). While other columns remain "with line width and X" because I might add more text but it will adjust the width accordingly. Can someone help me to do that? Thanks in advance. Just to keep in view, the other columns contain text only except colum 4. SO the two colum 3 and 4 are itemized text and all others are comprised of texts only

\documentclass[journal]{IEEEtran}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{cite}
\usepackage{url}
\usepackage[utf8]{inputenc}
\usepackage{comment}
\usepackage{multirow}
%\renewcommand{\q}[1]{``#1''}
%\usepackage[usestackEOL]{stackengine}
%\strutlongstacks{T}
\usepackage{makecell}
\usepackage{array}
\usepackage{array, caption, tabularx,  ragged2e,  booktabs}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{bbding}
\usepackage{pifont}
\usepackage{wasysym}
\usepackage{amssymb}
\newcommand{\xmark}{\ding{53}}
%\usepackage{spconf,amsmath,graphicx}
%\usepackage[caption=false]{subfig}
%
%\ifCLASSINFOpdf
%\else
%Packetized Energy—Current Status and Trends [Or]Recent Trends in ICT: Towards Packetized EnergyManagement/Energy Internet
%\fi
%\hyphenation{op-tical net-works semi-conduc-tor}


\begin{document}
\begin{table*}[t]
\caption{}
\renewcommand{\arraystretch}{1}
\tabcolsep=0.09cm
\label{Com}
\begin{tabularx}{\linewidth}{|>{\RaggedRight\arraybackslash}X|>{\RaggedRight\arraybackslash}X|>{\RaggedRight\arraybackslash}X|>{\RaggedRight\arraybackslash}X|>{\RaggedRight\arraybackslash}X|}
\hline

\multicolumn{1}{|>{\centering\arraybackslash}X|}{Technologies}
&
\multicolumn{1}{>{\centering\arraybackslash}X|}{{Reference(s)}}
&
\multicolumn{1}{>{\centering\arraybackslash}X|}{{sfasfdsafd}}
&
\multicolumn{1}{>{\centering\arraybackslash}X|}{{adfafdafdsfas}}
&
\multicolumn{1}{>{\centering\arraybackslash}X|}{{Views}}
&

\hline

\hline
\hline
ER and EH &    &\begin{itemize}
    \item dsafdafdsfafdafdfafdafasfdasfdasf
    \item afdfasfdafdsfasfdfasfdsfsafdffs
    \item sdafdfafdfasfdffafafdasfa
    \item sfafasfafasfsafsdfsafafaf 
\end{itemize}     &   & &\hline
 
 
 
 
IEM    &    &     &            &    \\ \hline




2& &  &     &            \\  \hline

3E&     &  &    &           \\            \hline


 4& & &     &  \\
 \hline
 
 5& & &    &   \\
 \hline
 
 
\hline
\end{tabularx}
\end{table*}
\end{document}
4
  • Welcome to TeX.SX!
    – leandriis
    Jun 16, 2020 at 18:00
  • 1
    Your code currently is not compilable because i) each table row should be ended with a \\ (these are entirely missing in your code), ii) you declare 5 columns but use 6 (hence the "Extra alignment tab has been changed to \cr." error) and iii) because >{\RaggedRight\arraybackslash}l is not a valid column decraration. Lastly, there is also a typo in \end{document}.
    – leandriis
    Jun 16, 2020 at 18:02
  • Please add some information on the contents of the columns. Column 3 seems to contain some itemize lists but what ybout the other columns? Will they contain longer texts, single words or numbers? Will you need linebreaks inside of the cells?
    – leandriis
    Jun 16, 2020 at 18:04
  • Hello Leandtriis, I totally agreed with what you said now I added you concerning information in the question again. Thanks
    – shane
    Jun 16, 2020 at 18:24

2 Answers 2

3

Here is a corrected version of your table. For the second column, I have used an l type column, The width of this column will automatically adapt to the widest entry. Linebreaks inside of this column are not supported.

Personally, I would use the booktabs package for just a few well spaced horizontal lines and entirely avoid using vertical lines.

enter image description here

\documentclass[journal]{IEEEtran}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{cite}
\usepackage{url}
\usepackage[utf8]{inputenc}
\usepackage{comment}
\usepackage{multirow}
%\renewcommand{\q}[1]{``#1''}
%\usepackage[usestackEOL]{stackengine}
%\strutlongstacks{T}
\usepackage{makecell}
\usepackage{array, caption, tabularx,  ragged2e,  booktabs}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{bbding}
\usepackage{pifont}
\usepackage{wasysym}
\usepackage{amssymb}
\newcommand{\xmark}{\ding{53}}
%\usepackage{spconf,amsmath,graphicx}
%\usepackage[caption=false]{subfig}
%
%\ifCLASSINFOpdf
%\else
%Packetized Energy—Current Status and Trends [Or]Recent Trends in ICT: Towards Packetized EnergyManagement/Energy Internet
%\fi
%\hyphenation{op-tical net-works semi-conduc-tor}


\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\usepackage{enumitem}
\newlist{tabitem}{itemize}{1}
\setlist[tabitem]{wide=0pt, nosep, leftmargin= * ,label=\textendash,after=\vspace{-\baselineskip},before=\vspace{-0.6\baselineskip}}


\begin{document}
\begin{table*}[t]
\caption{}
\renewcommand{\arraystretch}{1}
\tabcolsep=0.09cm
\label{Com}
\begin{tabularx}{\linewidth}{|L|l|L|L|L|}
\hline

\multicolumn{1}{|c|}{Technologies}
  & \multicolumn{1}{c|}{{Reference(s)}}
    & \multicolumn{1}{c|}{{sfasfdsafd}}
      & \multicolumn{1}{c|}{{adfafdafdsfas}}
        & \multicolumn{1}{c|}{{Views}} \\ \hline
\hline
ER and EH 
  &    
    &\begin{tabitem}
       \item dsafda fdsfafda fdfafd afasfdasf dasf
       \item afdf asfd afdsfa sfdf asfdsfsafd ffs
       \item sdafdf afdf asfdf afaf dasfa
       \item sfafa faf asf saf sdfsaf afaf 
     \end{tabitem}     
       & \begin{tabitem}
           \item dsafda fdsfafda fdfafd afasfdasf dasf
           \item afdf asfd afdsfa sfdf asfdsfsafd ffs
           \item sdafdf afdf asfdf afaf dasfa
           \item sfafa faf asf saf sdfsaf afaf 
         \end{tabitem}
         & some longer text in this column here \\ \hline

IEM   &  &  &  &  \\ \hline
2     &  &  &  &  \\ \hline
3E    &  &  &  &  \\ \hline
4     &  &  &  &  \\ \hline
5     &  &  &  &  \\ \hline

\end{tabularx}
\end{table*}
\end{document}

A horizontally centered first column and linebreaks in the second column can be achieved with one of the two following examples:

\documentclass[journal]{IEEEtran}
\usepackage{tabularx}
\usepackage{graphicx}
\usepackage{cite}
\usepackage{url}
\usepackage[utf8]{inputenc}
\usepackage{comment}
\usepackage{multirow}
%\renewcommand{\q}[1]{``#1''}
%\usepackage[usestackEOL]{stackengine}
%\strutlongstacks{T}
\usepackage{makecell}
\usepackage{array, caption, tabularx,  ragged2e,  booktabs}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{bbding}
\usepackage{pifont}
\usepackage{wasysym}
\usepackage{amssymb}
\newcommand{\xmark}{\ding{53}}
%\usepackage{spconf,amsmath,graphicx}
%\usepackage[caption=false]{subfig}
%
%\ifCLASSINFOpdf
%\else
%Packetized Energy—Current Status and Trends [Or]Recent Trends in ICT: Towards Packetized EnergyManagement/Energy Internet
%\fi
%\hyphenation{op-tical net-works semi-conduc-tor}


\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\usepackage{enumitem}
\newlist{tabitem}{itemize}{1}
\setlist[tabitem]{wide=0pt, nosep, leftmargin= * ,label=\textendash,after=\vspace{-\baselineskip},before=\vspace{-0.6\baselineskip}}


\begin{document}
\begin{table*}[t]
\caption{}
\renewcommand{\arraystretch}{1}
\tabcolsep=0.09cm
\label{Com}
\begin{tabularx}{\linewidth}{|C|p{1cm}|L|L|L|}
\hline

\multicolumn{1}{|c|}{Technologies}
  & \multicolumn{1}{c|}{{Reference(s)}}
    & \multicolumn{1}{c|}{{sfasfdsafd}}
      & \multicolumn{1}{c|}{{adfafdafdsfas}}
        & \multicolumn{1}{c|}{{Views}} \\ \hline
\hline
ER and EH 
  & text with linebreaks 
    &\begin{tabitem}
       \item dsafda fdsfafda fdfafd afasfdasf dasf
       \item afdf asfd afdsfa sfdf asfdsfsafd ffs
       \item sdafdf afdf asfdf afaf dasfa
       \item sfafa faf asf saf sdfsaf afaf 
     \end{tabitem}     
       & \begin{tabitem}
           \item dsafda fdsfafda fdfafd afasfdasf dasf
           \item afdf asfd afdsfa sfdf asfdsfsafd ffs
           \item sdafdf afdf asfdf afaf dasfa
           \item sfafa faf asf saf sdfsaf afaf 
         \end{tabitem}
         & some longer text in this column here \\ \hline

IEM   &  &  &  &  \\ \hline
2     &  &  &  &  \\ \hline
3E    &  &  &  &  \\ \hline
4     &  &  &  &  \\ \hline
5     &  &  &  &  \\ \hline

\end{tabularx}
\end{table*}


\begin{table*}[t]
\caption{}
\renewcommand{\arraystretch}{1}
\tabcolsep=0.09cm
\label{Com}
\begin{tabularx}{\linewidth}{|>{\hsize=1.15\hsize}C
                             |>{\hsize=0.4\hsize}L
                             |>{\hsize=1.15\hsize}L
                             |>{\hsize=1.15\hsize}L
                             |>{\hsize=1.15\hsize}L|}
\hline

\multicolumn{1}{|c|}{Technologies}
  & \multicolumn{1}{c|}{{Reference(s)}}
    & \multicolumn{1}{c|}{{sfasfdsafd}}
      & \multicolumn{1}{c|}{{adfafdafdsfas}}
        & \multicolumn{1}{c|}{{Views}} \\ \hline
\hline
ER and EH 
  &     text with linebreaks 
    &\begin{tabitem}
       \item dsafda fdsfafda fdfafd afasfdasf dasf
       \item afdf asfd afdsfa sfdf asfdsfsafd ffs
       \item sdafdf afdf asfdf afaf dasfa
       \item sfafa faf asf saf sdfsaf afaf 
     \end{tabitem}     
       & \begin{tabitem}
           \item dsafda fdsfafda fdfafd afasfdasf dasf
           \item afdf asfd afdsfa sfdf asfdsfsafd ffs
           \item sdafdf afdf asfdf afaf dasfa
           \item sfafa faf asf saf sdfsaf afaf 
         \end{tabitem}
         & some longer text in this column here \\ \hline

IEM   &  &  &  &  \\ \hline
2     &  &  &  &  \\ \hline
3E    &  &  &  &  \\ \hline
4     &  &  &  &  \\ \hline
5     &  &  &  &  \\ \hline

\end{tabularx}
\end{table*}
\end{document}
3
  • Great @leandriss, I picked your MWE, but here I have two related question 1) Can I center the entires in the first columns? why I couldn't use line break in the second column?
    – shane
    Jun 17, 2020 at 1:08
  • @shane: I have edited my question and included another MWE with two different examples that show how to achieve a horizontally centered first column as well as linebreaks in a narrow second column.
    – leandriis
    Jun 17, 2020 at 5:50
  • Excellent Leandriis, thanks
    – shane
    Jun 18, 2020 at 7:13
4
  • your document example (MWE: Minimal Working Example) doesn't work. Consider @leandriis comment and repair table code accordingly
  • unfortunately, your question is not clear
  • width of the second column is temporary adopted to the width of this column header, i.e. it can't be narrower that header width
  • since the contents of cells in this column is unknown, it is possible, that with longer text in cells will width of column will significantly enlarge
  • width use of the macro \widthof from the package package calc you can prescribe second column width equal to width of column header (see MWE below)
\documentclass[journal]{IEEEtran}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, tabularx}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\usepackage{caption}
\usepackage{enumitem}
\newlist{tabitem}{itemize}{1}   % <-- defined new list
\setlist[tabitem]{nosep,        % <-- new list setup
                 leftmargin=*,
                 label=\textbullet,
                 before=\begin{minipage}[t]{\linewidth}, % <---
                 after=\end{minipage}                   % <---
                 }
\usepackage{calc}               % for \widthof macro

\begin{document}
    \begin{table*}
\caption{My table}
\label{Com}
    \setcellgapes{3pt}
    \makegapedcells
\begin{tabularx}{\linewidth}{@{}L 
                                p{\widthof{ Reference(s) }} % column width is adopted 
                                                            % to width of column header
                                LLL @{}}
    \toprule
\makecell{Technologies}
    &   \makecell{Reference(s)}
        &   \makecell{sfasfdsafd}
            &   \makecell{adfafdafdsfas}
                &   \makecell{Views}        \\
    \midrule
ER and EH 
    &   &   \begin{tabitem}
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
           \end{tabitem}     
            &   &                           \\
2   &   &   \begin{tabitem}
2   &  here is some longer text in three lines
        &   \begin{tabitem}
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
           \end{tabitem}
            &   \begin{tabitem}
            \item dsafd afdsf afdaf dfafda fasf das fda sf
            \item dsafd afdsf afdaf dfafda fasf das fda sf
               \end{tabitem}
                &   \begin{tabitem}
                \item dsafd afdsf afdaf dfafda fasf das fda sf
                \item dsafd afdsf afdaf dfafda fasf das fda sf
                \item dsafd afdsf afdaf dfafda fasf das fda sf
                   \end{tabitem}            \\
3E  &   &   &   &                           \\
4   &   &   &   &                           \\
5   &   &   &   &                           \\
    \bottomrule
\end{tabularx}
    \end{table*}
\end{document}

enter image description here

Note: I took liberty in redesign your table. In this I exploit loaded packages:

  • booktabs for horizontal rules (\toprule, \midrule, \bottomrule)
  • remove vertical lines (they didn't work nicely with booktabs rules)
  • add package enumitem for defining tabitem, a itemize list for use in tables
  • increase vertical spaces in cells by use macros makegapedcells defined in makecell package
  • in my suggestions are considered (and loaded in MWE preamble) only packages relevant to the table.

In the case, that you more prefer table with vertical in horizontal lines, than replace booktab rules width \hline and add vertical lines specifiers to column specifications as you done in your MWE:

\documentclass[journal]{IEEEtran}
\usepackage{ragged2e}
\usepackage{booktabs, makecell, multirow, tabularx}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\usepackage{caption}
\usepackage{enumitem}
\newlist{tabitem}{itemize}{1}   % <-- defined new list
\setlist[tabitem]{nosep,        % <-- new list setup
                 leftmargin=*,
                 label=\textbullet,
                 before=\begin{minipage}[t]{\linewidth}, % <---
                 after=\end{minipage}                   % <---
                 }
\usepackage{calc}               % for \widthof macro

\begin{document}
    \begin{table*}
\caption{My table}
\label{Com}
    \setcellgapes{3pt}
    \makegapedcells
\begin{tabularx}{\linewidth}{|L 
                             |p{\widthof{ Reference(s) }} % column width is adopted 
                                                          % to width of column header
                             |L|L|L|}
    \hline
\makecell{Technologies}
    &   \makecell{Reference(s)}
        &   \makecell{sfasfdsafd}
            &   \makecell{adfafdafdsfas}
                &   \makecell{Views}        \\
    \hline
ER and EH 
    &   &   \begin{tabitem}
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
           \end{tabitem}     
            &   &                           \\
    \hline
2   &  here is some longer text in three lines
        &   \begin{tabitem}
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
        \item dsafd afdsf afdaf dfafda fasf das fda sf
           \end{tabitem}
            &   \begin{tabitem}
            \item dsafd afdsf afdaf dfafda fasf das fda sf
            \item dsafd afdsf afdaf dfafda fasf das fda sf
               \end{tabitem}
                &   \begin{tabitem}
                \item dsafd afdsf afdaf dfafda fasf das fda sf
                \item dsafd afdsf afdaf dfafda fasf das fda sf
                \item dsafd afdsf afdaf dfafda fasf das fda sf
                   \end{tabitem}            \\
    \hline
3E  &   &   &   &                           \\
    \hline
4   &   &   &   &                           \\
    \hline
5   &   &   &   &                           \\
    \hline
\end{tabularx}
    \end{table*}
\end{document}

enter image description here

4
  • I really appreciate your answer, I watched it late, but its very useful. I keep improving my table using the answer given by you and leandriss then I will mark tick. But Zarko here I have out of topic question which I have my account in StackExchange with some good reputation but when I opened my account yesterday everything is refreshed now It seems I made new account here, do you know the reason?
    – shane
    Jun 17, 2020 at 1:12
  • @shane, I'm very sorry, but I'm not familiar with site police. As far as I can see, you are new member of site (today from two days ago) and this is your first question. However 11 users have the same user name (except one all have reputation zero), what can confuse site administration.
    – Zarko
    Jun 17, 2020 at 6:49
  • Thanks. Yes your right but I had urgent question to ask and I couldn't find my old account that's why I went with the flow. Otherwise I have the account with a reputation score around 150 (not much) but at least better than a new account. TThe other things better than reputation are, the questions that I asked are really important.
    – shane
    Jun 18, 2020 at 7:18
  • @shane, you should contact site administration and ask for help in merging all your accounts in one. You also may ask for help from people in chat room chat.stackexchange.com/rooms/41/tex-latex-and-friends, how to do this. Anyway, with this account you already have rights to up-vote answers and accept the one, which you believe that the best fulfill your expectationbs :-)
    – Zarko
    Jun 18, 2020 at 9:32

You must log in to answer this question.

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