在文档标题中创建双框表格

在文档标题中创建双框表格

我对 TeX 还很陌生,现在我面临着在文档标题中创建双框表格的挑战。预期目标如下图所示: 表格应放在我的文档标题中。文本只是虚拟的。

结合这里的答案:

在表格中创建双线边框

通过谷歌搜索,我发现了这段代码:

\documentclass [a4paper, 12pt, twoside] {article}               
\usepackage [czech] {babel}                         
\usepackage [utf8] {inputenc}                           
\usepackage [left=2.5cm, right=2cm, headheight=110pt, top = 6.5cm, bottom=3cm] {geometry}       
\linespread{1.0}                                    
\usepackage{fancyhdr}
\usepackage{array}
\usepackage{multicol}

\setlength{\tabcolsep}{12pt}
\renewcommand{\arraystretch}{2.0}

\begin {document}

\nonfrenchspacing                                   

\pagestyle{fancy}
\renewcommand{\headrulewidth}{0pt}
\fancyhead[CE,CO,LE,LO,RE,RO]{} %% clear out all headers
\fancyhead[C]{% 
   \begin{table}
   \centering
   \setlength{\fboxrule}{1pt}
   \setlength{\fboxsep}{\doublerulesep}
     \fbox{%
     \setlength{\fboxsep}{0pt}%
       \fbox{%
       \begin{tabular}{m{2.5cm}|m{5cm}|m{2.5cm}|m{2.5cm}}
       \centering TEXT & \centering \LARGE{Another text} & Version: 2 & Page: \hspace{0.5pt}\thepage \hspace{0.5pt} / \pageref{LastPage} \\
\hline
\multicolumn{4}{c}{Long text}\\
\end{tabular}%
 }%
}
\end{table}
\end{tabular}
}
\end{document}

在文档主体中使用时效果很好,但我无法在标题中编译它,我找不到/找出原因。任何帮助或建议都很好!

提前谢谢你,Tomáš

答案1

虽然你的问题在campa的评论中得到了很好的解决:

姆韦 源代码:

\documentclass [a4paper, 12pt] {article}

% Code not relevant for tables, just to glamourize the examples :)
\parskip2em\parindent0pt  % warning: non LaTeX mode, good only for idlers
\usepackage[margin=2.25cm,showframe]{geometry}% show margins in green:
\makeatletter\def\Gm@hrule{}\def\Gm@hruled{}
\def\Gm@vrule{\color{green}\vrule width 1pt height\textheight depth\z@}%
\makeatother
\usepackage{array,lastpage,lipsum}
\renewcommand{\arraystretch}{2.0}
\def\longtext{So long text that will have linebreaks or not (that should not matter). Please, do not center if there are some line breaks.}
% Required for tables: 

\usepackage{hhline}
\usepackage{tabularx}
\newcolumntype{C}{>{\hfil}X}
\newcolumntype{P}{>{\centering}%
p{\dimexpr\linewidth-2\tabcolsep-2\doublerulesep-4\arrayrulewidth}}
\usepackage[table]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{booktabs}

\begin {document}

Your corrected code could produce  ...

\setlength{\tabcolsep}{12pt} % right LateX mode of setting  lenghts
\setlength{\fboxrule}{1pt}
\setlength{\fboxsep}{\doublerulesep}
\fbox{%
\setlength{\fboxsep}{0pt}%
\fbox{%
\begin{tabular}{m{2.5cm}|m{5cm}|m{2.5cm}|m{2.5cm}}
\centering TEXT & \centering \LARGE{Another text} & Version: 2 & Page: \hspace{0.5pt}\thepage \hspace{0.5pt} / \pageref{LastPage} \\\hline
\multicolumn{4}{c}{Not so long text that fit only in one line, but see the right  margin ...}\\
\end{tabular}%
}}

... or ...

\setlength{\tabcolsep}{12pt} % right LateX mode of setting  lenghts
\setlength{\fboxrule}{1pt}
\setlength{\fboxsep}{\doublerulesep}
\fbox{%
\setlength{\fboxsep}{0pt}%
\fbox{%
\begin{tabular}{m{2.5cm}|m{5cm}|m{2.5cm}|m{2.5cm}}
\centering TEXT & \centering \LARGE{Another text} & Version: 2 & Page: \hspace{0.5pt}\thepage \hspace{0.5pt} / \pageref{LastPage} \\\hline
\multicolumn{4}{c}{\longtext)}\\
\end{tabular}%
}}


But with a simpler code using \verb|hhline| and \verb|tabularx| thera are not this problem: 

\doublerulesep2pt
\arrayrulewidth1pt  

\begin{tabularx}{\linewidth}{||C|c|C|C||}
\hhline{|t:====:t|}
TEXT & \LARGE{Another text} & Version: 2 & Page: \thepage/\pageref{LastPage}
\\\hhline{||----||}
\multicolumn{4}{||P||}{\longtext}
\\\hhline{|b:====:b|}
\end{tabularx}%



Off-topic: although indiscutibly is a matter of individual taste, only in case that you want to escape from that  look of prehistoric HTML table, I would suggest some alternatives:



\newcolumntype{Q}{>{}p{\dimexpr\linewidth-2\tabcolsep}}

\tcbox[enhanced,
left=0mm,right=0mm,top=0mm,bottom=0mm,boxsep=1mm,boxrule=1pt,
arc=7mm,colframe=orange!50!black,colback=orange!05!white,
borderline={1pt}{1mm}{orange},
borderline={1pt}{1mm}{orange!50!black,dotted}]{\sffamily
\arrayrulecolor{orange}\renewcommand{\arraystretch}{2}%
\begin{tabularx}{\dimexpr\linewidth-4pt-1mm}{C|c|C|C}
TEXT & \LARGE{Another text} & Version: 2 & Page: \thepage/\pageref{LastPage} \\\hline
\multicolumn{4}{Q}{\longtext}\\
\end{tabularx}}


\sffamily
\rowcolors{1}{blue!10}{gray!10}
\arrayrulecolor{blue!50!black}
\begin{tabularx}{\linewidth}{CcCC}\toprule
\cellcolor{blue!25}TEXT & \cellcolor{blue!20}\LARGE{Another text} & \cellcolor{blue!15} Version: 2 & Page: \thepage/\pageref{LastPage} \\
\multicolumn{4}{Q}{\longtext}
\\\bottomrule
\end{tabularx}


\setcounter{page}{35}
\end{document}

相关内容