如何使用 TikZ 绘制以下框?
编辑(22.09)
答案1
不需要 tikZ,只需使用简单的 LaTeX 命令即可完成:
\documentclass{article}
\usepackage{tabularx}
\usepackage{xcolor}
\newcounter{tema}
\newenvironment{Tema}
{\par\noindent\refstepcounter{tema}\color{blue!80!black!40}\fboxrule=2pt
\fbox{\color{black}\bfseries Tema \thetema}\\[-1pt]% interlineskip
\color{black}\tabularx{\linewidth}
{!{\kern1em\color{blue!80!black!40}\vrule width 2pt}X @{}}~\\[-0.5\normalbaselineskip]}
{\endtabularx\par\bigskip}
\begin{document}
\begin{Tema}
Prominent think tanks, nonprofits known for their impartiality, have
received millions of dollars from foreign governments while pushing U.S.
officials to adopt policies that often reflect the donors’ priorities, an
investigation by The New York Times has found.\label{no1}
\end{Tema}
\begin{Tema}
Hundreds of people gathered in Manhattan to say goodbye to Joan Rivers,
who once wrote of the funeral she wanted: ``a huge showbiz affair with
lights, cameras, action''
\end{Tema}
\begin{Tema}
foo bar baz
\end{Tema}
As said in the New York Times (Tema~\ref{no1}) \ldots
\end{document}
对于长表来说也是一样:
[...]
\usepackage{longtable}
\newcounter{tema}
\newenvironment{Tema}
{\par\noindent\refstepcounter{tema}\color{blue!80!black!40}\fboxrule=2pt
\fbox{\color{black}\bfseries Tema \thetema}\\[\dimexpr-1pt-1.5\bigskipamount]
\color{black}\longtable
{!{\kern1em\color{blue!80!black!40}\vrule width 2pt}p{\dimexpr\linewidth-2pt-1em-\tabcolsep} @{}}~\\[-0.5\normalbaselineskip]
}
{\endlongtable\par}
[...]
答案2
另一个选择是tcolorbox
它提供auto counter
灵活的框架定义并处理分页符:
\documentclass{article}
\usepackage[most]{tcolorbox}
\usetikzlibrary{calc}
\newtcolorbox[auto counter]{tema}[1][]{colback=white, colframe=white,
coltitle=black,
title={\textsc{Tema}}~\thetcbcounter,#1,
enhanced,
breakable,
title code={%
\draw[very thick,blue!50!cyan!80!black]
(title.south west) rectangle
($(title.north west)!0.375!(title.north)$);%
},
interior titled code={%
\draw[very thick,blue!50!cyan!80!black]
([xshift=7pt]interior.north west) rectangle
([xshift=7pt]interior.south west);%
}
}
\begin{document}
\begin{tema}[label=no1]
Prominent think tanks, nonprofits known for their impartiality, have
received millions of dollars from foreign governments while pushing U.S.
officials to adopt policies that often reflect the donors’ priorities, an
investigation by The New York Times has found.
\end{tema}
\begin{tema}[label=x2]
Hundreds of people gathered in Manhattan to say goodbye to Joan Rivers,
who once wrote of the funeral she wanted: ``a huge showbiz affair with
lights, cameras, action''
\end{tema}
\begin{tema}
foo bar baz
\end{tema}
As said in the New York Times (Tema~\ref{no1} and Tema~\ref{x2}) \ldots
\end{document}
结果:
我建议进行以下小修改以改善整体外观:
\newtcolorbox[auto counter]{tema}[1][]{colback=white, colframe=white,
coltitle=black,
title={\textsc{Tema}}~\thetcbcounter,#1,
enhanced,
breakable,
title code={%
\draw[very thick,blue!50!cyan!80!black,
rounded corners, fill=white,
drop shadow={shadow yshift=-1.5pt,shadow xshift=1.5pt}] % <= load in the preamble \usetikzlibrary{shadows}
(title.south west) rectangle
($(title.north west)!0.375!(title.north)$);%
},
interior titled code={%
\draw[very thick,blue!50!cyan!80!black]
([xshift=7pt]interior.north west) rectangle
([xshift=7pt]interior.south west);%
}
}
其规定:
为了获得新的形状,无需加载shapes.callout
库,可以执行以下操作:
\newtcolorbox[auto counter]{tema}[1][]{colback=white, colframe=white,
coltitle=black,
title={\textsc{Tema}}~\thetcbcounter,#1,
enhanced,
breakable,
title code={%
\draw[very thick,blue!50!cyan!80!black]
(title.south west) |-
($(title.north west)!0.375!(title.north)$)--
($(title.south west)!0.375!(title.south)$)--++
(-0.45em,0)--++
(-115:2mm)--++
(125:2mm)--cycle
;%
},
interior titled code={%
\draw[very thick,blue!50!cyan!80!black]
([xshift=7pt]interior.north west) rectangle
([xshift=7pt]interior.south west);%
}
}
结果:
答案3
tcolorbox
带有标注的另一种变体:
\documentclass{article}
\usepackage[many]{tcolorbox}
\usetikzlibrary{shapes.callouts}
\tikzset{note/.style={rectangle callout,fill=#1}}
\newtcolorbox[auto counter]{mybox}[1][]{
colback=white,
left=0.5ex,
top=1ex,
right=0.5ex,
bottom=0ex,
arc=0pt,
outer arc=0pt,
leftrule=1pt,
rightrule=0pt,
toprule=0pt,
bottomrule=0pt,
breakable,
nobeforeafter,
enhanced jigsaw,
overlay={
\node[note=white,callout absolute pointer={([shift={(0.75in,-1ex)}]frame.north west)},callout pointer width=0.5cm,draw,line width=1pt,anchor=south west,align=center,minimum width=1in]
at ([shift={(-2ex,0ex)}]frame.north west) {Tema~\thetcbcounter};
},
before=\vspace*{2em}\noindent,
#1
}
\begin{document}
\begin{mybox}[label=no1]
This is some thing This is some thing This is some thing This is some thing This is
some thing This is some thing This is some thing This is some thing This is some
thing
\end{mybox}
\begin{mybox}[label=no2]
This is some thing This is some thing This is some thing This is some thing This is
some thing This is some thing This is some thing This is some thing This is some
thing
\end{mybox}
\end{document}
答案4
这是一种允许分页的方法,基于ntheorem
和framed
包。我将Tema
环境定义为嵌套在定理中的修补leftbar
环境(来自) ,定义为定理样式定理。此样式是对标准样式的修改,以便具有与左侧栏对齐的特殊类型的框架标签。framed
theme
framed-break
break
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[showframe, no marginpar]{geometry}
\usepackage{amssymb, amsfonts, amsmath}
\usepackage[x11names]{xcolor}
\usepackage{framed}
\usepackage{etoolbox}
\usepackage[framed]{ntheorem}
\usepackage{lipsum}
\colorlet{framecolour}{DeepSkyBlue3}
\colorlet{bgcolour}{SlateGray1!20!}
\colorlet{titlecolour}{Tomato3}
\makeatletter
\newtheoremstyle{framedbreak}%
{\item[\rlap{\vbox{\hbox{\hskip\dimexpr\labelsep-\theoremindent\relax\rlap{\fcolorbox{framecolour}{bgcolour}{\color{titlecolour}\theorem@headerfont
##1\ ##2\theorem@separator}}}}\hskip 1em \hbox{\smash{\color{framecolour}\rule[\dimexpr-1cm-\FrameSep+2\fboxrule \relax]{2pt}{1cm}}}}]\leavevmode}%
{\item[\rlap{\vbox{\hbox{\hskip\dimexpr\labelsep-\theoremindent\relax\rlap{\fcolorbox{framecolour}{bgcolour}{\color{titlecolour}\theorem@headerfont
##1\ ##2\ (##3)\theorem@separator}}}}\hskip 1em \hbox{\smash{\color{framecolour}\rule[\dimexpr-1cm-\FrameSep+\fboxrule \relax]{2pt}{1cm}}}}]\leavevmode}%
\makeatother
\parindent = 0pt
\setlength\fboxrule{2pt}
\theorempreskip{\bigskipamount}
\theorempostskip{\bigskipamount}
\theoremstyle{framedbreak}
\theorembodyfont{\upshape}
\newtheorem{theme}{Tema}
\renewenvironment{leftbar}{%
\def\FrameCommand{\hskip 1em{\color{framecolour}\vrule width 2pt} \hspace{0.333em}}%
\MakeFramed {\advance\hsize-\width \FrameRestore}}%
{\vskip 0.25ex\endMakeFramed}
%\setlength\FrameHeightAdjust{1cm}
\newenvironment{Tema}[1][]{%
\ifblank{#1}{\theme}{\theme[#1]}\leftbar}
{\endleftbar\endtheme}
\begin{document}
\begin{Tema}
Prominent think tanks, nonprofits known for their impartiality, have
received millions of dollars from foreign governments while pushing U.S.
officials to adopt policies that often reflect the donors’ priorities, an
investigation by The New York Times has found.\label{no1}
\end{Tema}
\begin{Tema}
Hundreds of people gathered in Manhattan to say goodbye to Joan Rivers,
who once wrote of the funeral she wanted: ``a huge showbiz affair with
lights, cameras, action''
\end{Tema}
\begin{Tema}[A Trial]
Prominent think tanks, nonprofits known for their impartiality, have received millions of dollars from foreign governments while pushing U.S. officials to adopt policies that often reflect the donors’ priorities, aninvestigation by The New York Times has found.
\end{Tema}
\lipsum[2]
\begin{Tema}%
\lipsum[1-4]
\end{Tema}
\end{document}