微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将 tabularx 标题和单元格/列与“逐项内容”对齐,加上表格边框未连接

如何解决将 tabularx 标题和单元格/列与“逐项内容”对齐,加上表格边框未连接

我有如下 Tabularx 结构,如何根据我的需要对齐每个列或单元格,特别是单元格或列与逐项列出的项目。目前,逐项对齐的项目右对齐,我想居中或左对齐。如何将标题对齐到中心?另外,拐角处的交叉点没有连接!!!。我该怎么办?

先谢谢你

文档如下:

\begin{document}
    \begin{tabularx}{\textwidth}{|*{3}{>{\compress}X|}}
        \caption{caption}
        \label{tab:table1lable}                             \\
        \toprule
        head1 & head2 & head3         \\            
        \midrule
        \endfirsthead
        %---------------------------------------------------------------%
        \caption{caption} \\  %\hfill(continued)
        \toprule
        head1 & head2 & head3 \\         
        \midrule
        \endhead
        %---------------------------------------------------------------%
        \multicolumn{3}{r}{\footnotesize\textit{continued on the next page}}
        \endfoot
        \bottomrule
        \endlastfoot
        
        \hline
        A&B&C\\
        \hline
        col1\_content & 
        \begin{itemize}
            \item col2 list item1
            \item col2 list item2
        \end{itemize} &
         
        \begin{itemize}
            \item col3 list item1
            \item col3 list item2
        \end{itemize}
    \end{tabularx}
\end{document}

完整的乳胶包和序言如下:

\documentclass[
%draft,final,paper=a4,paper=portrait,fontsize=12pt,version=last,twoside,ngerman,titlepage,toc=listof,toc=bibliography,usenames,dvipsnames,svgnames,table
]{scrbook}

\usepackage[a4paper,left=3cm,right=4cm,top=2cm,bottom=3cm]{geometry}
\usepackage[T1]{fontenc}
%\usepackage[ngerman]{babel}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage[babel]{csquotes}
%\usepackage[babel,german=quotes]{csquotes}
\usepackage[super]{nth}
%    
\usepackage{mathptmx}%
\usepackage{tabularx}    
\usepackage{setspace}
\onehalfspacing
% Fix for floats
\usepackage{scrhack}    
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}   
\usepackage{xcolor}   
\usepackage{textcomp}
\usepackage{booktabs}   
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}    
\usepackage{hyperref}    
\usepackage{caption}
% Fehler mit nicht zentrierten Captions beheben
\captionsetup{width=2\textwidth}

\usepackage{graphicx}
\usepackage{wrapfig}

\usepackage{ifdraft}
\ifdraft{\let\ifxdraft\iftrue}{\let\ifxdraft\iffalse}

% Hurenkind und Schusterjunge
\clubpenalty = 10000
\widowpenalty = 10000
\displaywidowpenalty = 10000

\usepackage{listings}

\lstdefinestyle{code}{
    backgroundcolor=\color{white},basicstyle=\footnotesize\ttfamily,breakatwhitespace=false,breaklines=true,captionpos=b,commentstyle=\color{blue},extendedchars=true,frame=single,identifierstyle=,keepspaces=true,keywordstyle=\color{Sepia},language=C,numbers=left,numbersep=5pt,numberstyle=\tiny\color{gray},rulecolor=\color{black},showspaces=false,showstringspaces=false,showtabs=false,stepnumber=1,stringstyle=\color{orange},tabsize=1,title=\lstname
}

\lstdefinestyle{text}{
    backgroundcolor=\color{white},title=\lstname
}

\usepackage{enumitem}
\usepackage{tabularx,makecell}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{ltablex}
\keepXColumns

\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother

%

\usepackage{colortbl} % color table
\definecolor{maroon}{cmyk}{0,0.87,0.68,0.32}
\newcommand{\gray}{\rowcolor[gray]{.90}}

%
\usepackage{xargs}                      % Use more than one optional parameter in a new commands

\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
% caption for tabular x
\usepackage{siunitx} % SI Unit
\usepackage{marginnote} % add margin note 
%\marginnote{This is a margin note using the geometry package,set at 3cm vertical offset to the line it is typeseted.}[3cm]

\usepackage{tabularx} % table



\title{Business Intelligence to Support an Indicator-Based Waste Incineration Process}
\author{Mohammadjavad Ranji}
\date{\today}

\makeatletter
\let\ThesisTitle\@title
\let\ThesisDate\@date
\makeatother

\begin{document}
    
    
    
    \begin{tabularx}{\textwidth}{|*{3}{>{\compress}X|}}
        \caption{caption}
        \label{tab:table1lable}                             \\
        \toprule
        head1 & head2 & head3         \\            
        \midrule
        \endfirsthead
        %---------------------------------------------------------------%
        \caption{caption} \\  %\hfill(continued)
        \toprule
        head1 & head2 & head3 \\         
        \midrule
        \endhead
        %---------------------------------------------------------------%
        \multicolumn{3}{r}{\footnotesize\textit{continued on the next page}}
        \endfoot
        \bottomrule
        \endlastfoot
        
        \hline
        A&B&C\\
        \hline
        col1\_content & 
        \begin{itemize}
            \item col2 list item1
            \item col2 list item2
        \end{itemize} &
         
        \begin{itemize}
            \item col3 list item1
            \item col3 list item2
        \end{itemize}
    \end{tabularx}
\end{document}

解决方法

  • 避免表格单元格周围线条出现间隙的最佳方法是不要使用垂直线条。查看 booktabs 包的用户指南,了解有关如何获得具有专业外观的桌子的更多信息

  • 当您使用 enumitem 包时,您可以设置 leftmargin 以避免单元格左侧的额外水平空间


\documentclass{scrbook}
    
\usepackage{enumitem}
\usepackage{makecell}
\usepackage{booktabs}
\usepackage{ltablex}
\keepXColumns

\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\makeatother
\usepackage{tabularx} % table


\begin{document}
    
    
    
    \begin{tabularx}{\textwidth}{@{}*{3}{>{\compress}X}@{}}
        \caption{caption}
        \label{tab:table1lable}                             \\
        \toprule
        head1 & head2 & head3         \\     
        \cmidrule(r){1-1}   \cmidrule(lr){2-2}   \cmidrule(l){3-3}     
        \endfirsthead
        %---------------------------------------------------------------%
        \caption{caption} \\  %\hfill(continued)
        \toprule
        head1 & head2 & head3 \\         
        \cmidrule(r){1-1}   \cmidrule(lr){2-2}   \cmidrule(l){3-3}     
        \endhead
        %---------------------------------------------------------------%
        \multicolumn{3}{r}{\footnotesize\textit{continued on the next page}}
        \endfoot
        \bottomrule
        \endlastfoot
        
        
        A&B&C\\
        \addlinespace
        
        col1\_content & 
        \begin{itemize}[leftmargin=*]
            \item col2 list item1
            \item col2 list item2
        \end{itemize} &
         
        \begin{itemize}[leftmargin=*]
            \item col3 list item1
            \item col3 list item2
        \end{itemize}
    \end{tabularx}
\end{document}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。