这是我的问题,
我正在尝试仅修复第二列的宽度(即减小)。而其他列仍保持“带有线宽和 X”,因为我可能会添加更多文本,但它会相应地调整宽度。有人能帮我做到这一点吗?提前谢谢。请注意,除第 4 列外,其他列仅包含文本。因此,第 3 列和第 4 列是分项文本,所有其他列仅由文本组成
\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}
答案1
这是您表格的更正版本。对于第二列,我使用了一种l
类型列,此列的宽度将自动适应最宽的条目。不支持此列内的换行符。
就我个人而言,我会使用该booktabs
包装仅画出几条间距适当的水平线,完全避免使用垂直线。
\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}
可以通过以下两个示例之一来实现第一列水平居中和第二列换行:
\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}
答案2
- 您的文档示例(MWE:最小工作示例)不起作用。考虑@leandriis 的评论并相应地修复表格代码
- 不幸的是,你的问题不清楚
- 第二列的宽度暂时采用该列标题的宽度,即不能小于标题宽度
- 由于此列中单元格的内容未知,因此单元格中的文本越长,列宽可能会显著增大
\widthof
width 使用包中的宏,calc
您可以规定第二列的宽度等于列标题的宽度(参见下面的 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
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}
注意:我擅自重新设计了您的表格。在此我利用了已加载的包:
booktabs
对于水平线 (\toprule
,\midrule
,\bottomrule
)- 删除垂直线(它们与
booktab
删除垂直线(它们与s 规则 - 添加
enumitem
用于定义tabitem
表格中使用的逐项列表的包 - 通过使用包
makegapedcells
中定义的宏来增加单元格中的垂直空间makecell
- 在我的建议中仅考虑与表相关的包(并将其加载到 MWE 序言中)。
在这种情况下,您更喜欢在水平线上有垂直线的表格,而不是替换booktab
规则宽度\hline
并将垂直线说明符添加到列规范中,就像在 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}