具有两列和一个标题的框架

具有两列和一个标题的框架

我需要制作一个有两个框和一个标题的框架,如下图所示:

带有分隔空间的两列框架和一个块标题

我当前的代码如下:

\documentclass{article}
\usepackage{array}
\usepackage[top=1cm, left=2cm,right=2cm {geometry}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
\node[text width=7.7cm,draw,minimum size=5cm,align=center] (esq) {\vspace*{.7cm}\rule{1cm}{.2pt}/\rule{1cm}{.2pt}/\rule{1.5cm}{.2pt}\\\rule{5cm}{.25pt}\\Signature\\Person 1};
\node[text width=7.7cm, right=.7cm of esq,draw,align=center, minimum size=5cm] (dir) {\vspace*{.7cm}\rule{1cm}{.2pt}/\rule{1cm}{.2pt}/\rule{1.5cm}{.2pt}\\\rule{5cm}{.25pt}\\Signature\\Person 2};
\node[inner sep=1.5ex,text width=10.25cm,right=1.5cm of esq.north west,xshift=1.35cm, draw=white,line width=5pt,fill=black!10,align=center,font=\bfseries\sffamily] (topo) {\Large \bf \textsc{Agreement}};
\draw (topo.south west) rectangle (topo.north east);
\end{tikzpicture}
\end{document}

我的问题与标题框“协议”的定位有关。例如,如果页面宽度发生变化,我需要找到一个新位置。我没能将它定位到两个框之间的中心。

如何设置标题框相对于框的位置?我也尝试使用 tcolorbox 执行此操作,但没有成功。可能吗?

答案1

您可以使用 calc 库并找到标题

at ( $ (esq.north)!0.5!(dir.north) $) 

完整代码:

\documentclass{article}
\usepackage{tikz}
\usepackage{array}
\usepackage[top=1cm, left=2cm,right=2cm]{geometry}
\usetikzlibrary{positioning,calc}

\begin{document}
\begin{tikzpicture}
\node[text width=7.7cm,draw,minimum size=5cm,align=center] 
  (esq) 
  {\vspace*{.7cm}\rule{1cm}{.2pt}/\rule{1cm}{.2pt}/\rule{1.5cm}{.2pt}\\\rule{5cm}{.25pt}\\Signature\\Person 1};

\node[text width=7.7cm, right=.7cm of esq,draw,align=center, minimum size=5cm] 
  (dir) 
  {\vspace*{.7cm}\rule{1cm}{.2pt}/\rule{1cm}{.2pt}/\rule{1.5cm}{.2pt}\\\rule{5cm}{.25pt}\\Signature\\Person 2};

\node[inner sep=1.5ex,text width=10.25cm,draw=white,line width=5pt,fill=black!10,align=center,font=\bfseries\sffamily] 
  (topo)
  at ( $ (esq.north)!0.5!(dir.north) $) 
  {\Large\bfseries\textsc{Agreement}};
\draw (topo.south west) rectangle (topo.north east);
\end{tikzpicture}

\end{document}

在此处输入图片描述

使用tcolorbox及其raster库,您可以执行如下操作(调整设置):

\documentclass{article}
\usepackage[many]{tcolorbox}
\usepackage{array}
\usepackage[top=1cm, left=2cm,right=2cm]{geometry}
\usetikzlibrary{positioning,calc}

\begin{document}

\begin{tcbraster}[
  raster columns=2, 
  raster equal height,
  enhanced,
  colframe=black,
  colback=white,
  arc=0pt,
  outer arc=0pt,
  halign=center
  ]
\begin{tcolorbox}[remember as=left]
\vspace*{.7cm}
\rule{1cm}{.2pt}/\rule{1cm}{.2pt}/\rule{1.5cm}{.2pt}\\
\rule{5cm}{.25pt}\\
Signature\\
Person 1
\end{tcolorbox}
\begin{tcolorbox}[remember as=right]
\vspace*{.7cm}
\rule{1cm}{.2pt}/\rule{1cm}{.2pt}/\rule{1.5cm}{.2pt}\\
\rule{5cm}{.25pt}\\
Signature\\
Person 2
\end{tcolorbox}
\end{tcbraster}
\begin{tikzpicture}[overlay,remember picture,overlay]
\node[inner sep=1.5ex,text width=10.25cm,draw=white,line width=5pt,fill=black!10,align=center,font=\bfseries\sffamily] 
  (topo)
  at ( $ (left.north)!0.5!(right.north) $) 
  {\Large\bfseries\textsc{Agreement}};
\draw (topo.south west) rectangle (topo.north east);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容