如何使用 LaTeX 创建以下带有文本的框?

如何使用 LaTeX 创建以下带有文本的框?

请帮我创建以下带有图片中所示文本的框。我编写了以下代码,结果如下。但我对结果和前景仍不满意。如能得到任何帮助,我将不胜感激。提前致谢。

在此处输入图片描述

\documentclass[12pt]{exam}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage{tcolorbox}
\usepackage{graphicx}
\usepackage[hmargin=0.8in,vmargin=0.5in]{geometry}
\usepackage{array}
\usepackage{setspace}
\newcommand*\diff{\mathop{}\!\mathrm{d}}
\newcommand*\Diff[1]{\mathop{}\!\mathrm{d^#1}}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}


\begin{document}

\begin{tcolorbox}

Write your name here\\
\begin{tabular}{|l|r|}
\hline
\scriptsize{Surname} \hspace{8cm} & \scriptsize{\hspace{4.5cm}Other Names \hspace{3cm}}\\[5mm]
\hline
\end{tabular}
\\[2mm]
\vspace{0.5in}
\begin{tabular}{lrr}
\Large{\textbf{AHS Examinations}} \hspace{6cm}& Center Number \hspace{2cm}& Candidate Number\\
\textbf{Semester 4} \hspace{4cm}&\begin{tabular}{|c|c|c|c|c|}\hline & & & & \\ \hline\end{tabular}  &\hspace{3.5cm} \begin{tabular}{|c|c|c|c|c|}\hline & & & \\ \hline\end{tabular}\\
\textbf{Advanced Level} & &  
\end{tabular}


\begin{tabular}{|l|c|}
\hline

\huge{\textbf{Core Mathematics C12}} &\\
\textbf{Advanced Subsidiary}  & \\[5mm]

\hline
April, 2017 \hspace{11cm} & \scriptsize{Paper Reference} \\
\textbf{Time: 1 hours 30 minutes} & \textbf{WMA01/01}\\
\hline
\end{tabular}
\\\\
\fbox{\parbox{13.5cm}{\textbf{You must have:}\\
Mathematical Formulae and Statistical Tables (Blue) \\}} \fbox{\parbox{2cm}{\scriptsize{Total Marks \hspace{2cm}}\\\\\\}}
\end{tcolorbox}

\end{document}

答案1

为了实现如此复杂的布局,tcolorbox需要很多技巧:

  • tcbraster
  • raster multicolumn
  • overlay将平移的垂直线绘制到分割线节点
  • 使用特殊的分割方式
  • sidebyside选项

  • 使用tabularx的关键tcolorbox 和一些技巧来获得具有圆角的表格。

  • 一种没有框架的盒子样式,称为notcb

\documentclass[12pt]{exam}
\usepackage{amsmath,amsthm,amssymb,amsfonts}
\usepackage{array}
\usepackage{tabularx}
\usepackage[table]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{graphicx}
\usepackage[hmargin=0.8in,vmargin=0.5in]{geometry}
\usepackage{array}
\usepackage{setspace}
\newcommand*\diff{\mathop{}\!\mathrm{d}}
\newcommand*\Diff[1]{\mathop{}\!\mathrm{d^#1}}

\newcommand{\N}{\mathbb{N}}
\newcommand{\Z}{\mathbb{Z}}

% A style for tcolorbox without frame etc. "notcb"
\tcbset{notcb/.style={enhanced jigsaw, colback=white, coltitle=black,sharp corners, boxrule=0pt}}

% Style for the number tables
\tcbset{tabularheader/.style={arc=2pt,natural height,notcb,boxsep=0pt,left=0pt,colbacktitle=white,rounded corners=all,enhanced jigsaw,coltitle=black,tabularx={*{4}{Y|}Y},boxrule=1pt,attach boxed title to top left, boxed title style={enhanced jigsaw,sharp corners,left=0pt,boxrule=0pt}}}

\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}


\begin{tcolorbox}[colback=white]



Write your name here
\begin{tcbraster}[raster columns=1, raster column skip=0pt, raster equal height,colback=white,before skip=0pt]
  \begin{tcolorbox}[coltitle=black,enhanced jigsaw,boxrule=0.5pt,boxsep=0.5pt,segmentation style={solid,black,line width=0.5pt},sidebyside,
    righthand width=4cm,fontupper=\normalsize,
    ]
    Surname
    \bigskip
    \tcblower
    Other names
    \bigskip
  \end{tcolorbox}
\end{tcbraster}
\begin{tcbraster}[raster columns=3,raster equal height]
  \begin{tcolorbox}[notcb,fontupper=\bfseries\raggedright]
    {\Large \vphantom{y}AHS Examinations}

    Semester 4

    Advanced Level

    \end{tcolorbox}
    \begin{tcolorbox}[tabularheader,title={Center Number}]
      & & & & \tabularnewline
    \end{tcolorbox}
    \begin{tcolorbox}[tabularheader,title={Candidate Number}]
      & & & & \\
    \end{tcolorbox}
  \end{tcbraster}
  \begin{tcolorbox}[enhanced jigsaw,fontupper=\bfseries,colback=white,segmentation style={solid,tcbcol@frame,line width=2pt},underlay={
    \draw[tcbcol@frame,line width=1pt] ([xshift={5cm}]frame.south) -- ([xshift={5cm}]segmentation.center);
  }
  ]
  {\Large Core Mathematics C12}

  Advanced Subsidiary
  \bigskip
  \tcblower
  Wednesday  April 2017 \hfill {\raggedright \scriptsize Paper Reference}

  Time 1 hour 30 minutes \hfill\raggedright WMA01/01
\end{tcolorbox}
\begin{tcbraster}[raster columns=6,raster equal height,boxsep=0.5pt]
\begin{tcolorbox}[colback=white,raster multicolumn=5]
  {\large \textbf{You must have:} }

  Mathematical Formulae and Statistical Tables (Blue)
  \bigskip
\end{tcolorbox}
\begin{tcolorbox}[colback=white,left=2pt,right=2pt]
  Total Marks

  \bigskip
\end{tcolorbox}
\end{tcbraster}
\end{tcolorbox}

\end{document}

\begin{tcolorbox}


Write your name here\\
\begin{tabular}{|l|r|}
\hline
\scriptsize{Surname} \hspace{8cm} & \scriptsize{\hspace{4.5cm}Other Names \hspace{3cm}}\\[5mm]
\hline
\end{tabular}
\\[2mm]
\vspace{0.5in}
\begin{tabular}{lrr}
\Large{\textbf{AHS Examinations}} \hspace{6cm}& Center Number \hspace{2cm}& Candidate Number\\
\textbf{Semester 4} \hspace{4cm}&\begin{tabular}{|c|c|c|c|c|}\hline & & & & \\ \hline\end{tabular}  &\hspace{3.5cm} \begin{tabular}{|c|c|c|c|c|}\hline & & & \\ \hline\end{tabular}\\
\textbf{Advanced Level} & &  
\end{tabular}


\begin{tabular}{|l|c|}
\hline

\huge{\textbf{Core Mathematics C12}} &\\
\textbf{Advanced Subsidiary}  & \\[5mm]

\hline
April, 2017 \hspace{11cm} & \scriptsize{Paper Reference} \\
\textbf{Time: 1 hours 30 minutes} & \textbf{WMA01/01}\\
\hline
\end{tabular}
\\\\
\fbox{\parbox{13.5cm}{\textbf{You must have:}\\
Mathematical Formulae and Statistical Tables (Blue) \\}} \fbox{\parbox{2cm}{\scriptsize{Total Marks \hspace{2cm}}\\\\\\}}
\end{tcolorbox}


\end{document}

在此处输入图片描述

相关内容