我正在尝试在 TikZ 中创建一个带有一些文本的彩色框。这是我的脏代码:
\documentclass[a4paper,12pt]{extreport}
\usepackage{fontspec}
\usepackage{pgf}
\usetikzlibrary{calc}
\usepackage{lipsum}
\usepackage{color}
\begin{document}
\begin{tikzpicture}[every node/.style={inner sep=0pt}]
\node[text width=15cm,align=center,fill=green](Text){%
\lipsum[1-2]};
\node[circle,draw=black,shift={(-1cm,1cm)},anchor=north west](CNW) at (Text.north west) {text};
\node[circle,draw=black,shift={(1cm,1cm)},anchor=north east](CNE) at (Text.north east) {text};
\node[circle,draw=black,shift={(-1cm,-1cm)},anchor=south west](CSW) at (Text.south west) {text};
\node[circle,draw=black,shift={(1cm,-1cm)},anchor=south east](CSE) at (Text.south east) {text};
\end{tikzpicture}
\end{document}
我想知道如何让标记为“文本”的节点的宽度等于 \textwidth(无论文档中的数字是多少;节点的高度应该可以容纳其中的任何文本量)。节点应该位于页面中央,但是,当我尝试将 \textwidth 替换为 15cm 时,图片会超出页面。欢迎提出任何建议!
答案1
也许你可以考虑tcolorbox
这种事情。下面是一个制作类似于所需盒子的例子。它需要进行调整并决定如何考虑盒子周围的空间,但可以给出一个想法。
\documentclass[a4paper,12pt]{extreport}
\usepackage{fontspec}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\begin{document}
\begin{tcolorbox}[enhanced, colback=green!30,
overlay={
\node[circle,draw, above left=5mm of frame.north west] {text};
\node[circle,draw, above right=5mm of frame.north east] {text};
\node[circle,draw, below left=5mm of frame.south west] {text};
\node[circle,draw, below right=5mm of frame.south east] {text};
}
]
\lipsum[1-2]
\end{tcolorbox}
\begin{tcolorbox}[enhanced, colback=green!30,
width=10cm, center,
overlay={
\node[circle,draw, above left=5mm of frame.north west] {text};
\node[circle,draw, above right=5mm of frame.north east] {text};
\node[circle,draw, below left=5mm of frame.south west] {text};
\node[circle,draw, below right=5mm of frame.south east] {text};
}
]
\lipsum[1-2]
\end{tcolorbox}
\end{document}