我正在尝试构建一个龙与地下城风格的 LaTeX 模板,并想重新创建如下所示的特定盒子风格:
使用蒂克兹我设法重新创建了粗略的形状,但我不知道如何......
- 垂直缩放框以适合文本
- 将文本放入框中,框会自动换行以适应右边距
如能提供任何帮助我将非常感激:-)。
梅威瑟:
\documentclass[10pt,twoside]{article}
\usepackage{multicol}
\usepackage{tikz} %for quotebox
\let\svtikzpicture\tikzpicture %remove left indent for tikz picture
\def\tikzpicture{\noindent\svtikzpicture} %remove left indent for tikz picture
\begin{document}
\begin{multicols}{2}
\begin{tikzpicture}
\path [fill=gray] (0,0) rectangle (\linewidth,10em);
\draw [red, thick] (0,0) -- (0,10em);
\draw [red,fill] (0,0) circle [radius=0.05];
\draw [red,fill] (0,10em) circle [radius=0.05];
\draw [red,thick] (\linewidth,0) -- (\linewidth,10em);
\draw [red, fill] (\linewidth,0) circle [radius=0.05];
\draw [red, fill] (\linewidth,10em) circle [radius=0.05];
\node at (1em,5em) {text};
\end{tikzpicture}
\end{multicols}
\end{document}
答案1
我和克里斯蒂安有同样的想法,但由于我的实现看起来更像原始版本,所以我发布了另一个答案。
\documentclass{article}
\usepackage[most]{tcolorbox}
\definecolor{background}{HTML}{FCF9EE}
\definecolor{linecolor}{HTML}{581810}
\begin{document}
\begin{tcolorbox}[
enhanced,
boxsep=0.25ex,
arc=0mm,
borderline west={1pt}{-0.5pt}{linecolor},
borderline east={1pt}{-0.5pt}{linecolor},
colback=background,
colframe=background,
overlay={
\foreach \n in {north east,north west,south east,south west}
{\draw [linecolor, fill=linecolor] (frame.\n) circle (2pt); }; }]
\begin{description}
\item[Dungeon Master (DM):] OK, one at a time. Phillip, you are looking at the gargoyles?
\item[Phillip:] Yeah. Is there any hint they might be creatures and not decorations?
\item[DM:] Make an Intelligence check.
\item[Phillip:] Does my Investigation skill apply?
\item[DM:] Sure!
\item[Phillip (rolling a d20):] Ugh. Seven.
\item[DM:] They look like decorations to you. And Amy, Riva is checking out the drawbridge?
\end{description}
\end{tcolorbox}
\end{document}
编辑:
由于您可能希望在文档中多次使用此框,因此根据tcolorbox
以下内容定义新环境是有意义的:
\newtcolorbox{dungeonbox}{enhanced,
boxsep=0.25ex,
arc=0mm,
borderline west={1pt}{-0.5pt}{linecolor},
borderline east={1pt}{-0.5pt}{linecolor},
colback=background,
colframe=background,
overlay={
\foreach \n in {north east,north west,south east,south west}
{%
\draw [linecolor, fill=linecolor] (frame.\n) circle (2pt);
};
}
}
然后您就可以像这样轻松使用它:
\begin{dungeonbox}
...
\end{dungeonbox}
答案2
这是tcolorbox
附加overlay
内容等等。它是易碎的。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[most]{tcolorbox}
\usepackage{blindtext}
\newlength{\vertlinewidth}
\setlength{\vertlinewidth}{1pt}
\newlength{\vertlineoffset}
\setlength{\vertlineoffset}{-5pt}
\newlength{\circleradius}
\setlength{\circleradius}{3pt}
\newlength{\circleoffset}
\setlength{\circleoffset}{0pt}
\definecolor{dungeoncolor}{RGB}{255,0,0}
\newtcolorbox{dungeonbox}[1][]{enhanced jigsaw,frame hidden,boxrule=0pt,
breakable,
sharp corners,
drop lifted shadow,
colback=white!90!black,
borderline vertical={\vertlinewidth}{\vertlineoffset}{dungeoncolor},
overlay={opacity=1.0,
\node (A) at (frame.north west) {};\draw[fill,dungeoncolor] ($(A) + (\vertlineoffset-\vertlinewidth+0.5\circleradius,\circleoffset+\circleradius)$) circle (\circleradius);
\node (B) at (frame.south west) {};\draw[fill,dungeoncolor] ($(B) + (\vertlineoffset-\vertlinewidth+0.5\circleradius,-\circleoffset-\circleradius)$) circle (\circleradius);
\node (C) at (frame.south east) {};\draw[fill,dungeoncolor] ($(C) + (-\vertlineoffset+\vertlinewidth-0.5\circleradius,-\circleoffset-\circleradius)$) circle (\circleradius);
\node (D) at (frame.north east) {};\draw[fill,dungeoncolor] ($(D) + (-\vertlineoffset+\vertlinewidth-0.5\circleradius,\circleoffset+\circleradius)$) circle (\circleradius);},
#1
}
\begin{document}
\begin{dungeonbox}
\blindtext[10]
\end{dungeonbox}
\end{document}
答案3
您可以在制作矩形的同时填写文本。利用节点默认为矩形形状的事实(?)。Tikz 会自动神奇地调整矩形的大小。由于您似乎只想要垂直调整,请指定框的水平大小。为此,您可以指定文本的宽度,以便 Tikz 知道在哪里中断长句子( ) text width =
。可能有一种简单的方法可以通过指定节点自动绘制红线和圆圈/.style
,但我不知道该怎么做。我使用矩形节点的角来定位红线和圆圈。anchors
north east
\documentclass[10pt,twoside]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
% make a node (rectangle)
% filled with gray
% occuplying half the current \textwidth
% name it mybox for reffering later
% add the text to it right away so that tikz can
% calculate how big the box should be
\node [fill=gray, text width=0.5\textwidth] (0,0) (mybox)
{%
\begin{description}
\item [dungeon master] says Hi.
\item [player one] says Hi.
\item [player two] says Hi.
\item [player three] says Hi.
\end{description}
};
%use the above node's anchors to position the red lines and circles
\draw [red, thick] (mybox.south west) -- (mybox.north west);
\draw [red,fill] (mybox.south west) circle [radius=0.05];
\draw [red,fill] (mybox.north west) circle [radius=0.05];
\draw [red,thick] (mybox.south east) -- (mybox.north east);
\draw [red, fill] (mybox.south east) circle [radius=0.05];
\draw [red, fill] (mybox.north east) circle [radius=0.05];
\end{tikzpicture}
\end{document}