![删除用 tikz 制作的彩色框中的压痕](https://linux22.com/image/261461/%E5%88%A0%E9%99%A4%E7%94%A8%20tikz%20%E5%88%B6%E4%BD%9C%E7%9A%84%E5%BD%A9%E8%89%B2%E6%A1%86%E4%B8%AD%E7%9A%84%E5%8E%8B%E7%97%95.png)
我有一份如下所示的文档:
代码如下:
\documentclass[10pt]{memoir}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds,patterns}
\tikzstyle{box} = [align=center, text width=12.4cm, draw=blue, fill=blue, rectangle, rounded corners,
inner sep=5pt, inner ysep=5pt]
\begin{document}
\lipsum
~\\
\begin{tikzpicture}
\node[box](box){\color{white}\textbf{white text on blue background}};
\node[shape=circle,fill=white,inner sep=2mm] at (box.west) {};
\node[text=blue,right=-3pt] at (box.west) {\textbf{1}};
\end{tikzpicture}
~\\
\lipsum
\end{document}
我希望tikzpicture
不缩进并与文本垂直对齐。我\noindent
之前 尝试过\begin{tikzpicture}
,但似乎不起作用...
有什么建议吗?
答案1
如果您添加draw
到圆圈节点,您将看到您的框与文本对齐。如果您不希望将圆圈的左侧计入边界框,请使用overlay
:
\node[shape=circle,fill=white,inner sep=2mm, overlay] at (box.west) {};
更好的解决方案是连接最后两个节点:
\lipsum
~\\
\begin{tikzpicture}
\node[box](box){\color{white}\textbf{white text on blue background}};
\node[shape=circle,fill=white,
text=blue,right=-3pt] at (box.west) {\textbf{1}};
\end{tikzpicture}
~\\
\lipsum
答案2
白色圆圈构成了 的边界框。可以通过选项inner sep \hspace*`(行首的星号形式)tikzpicture
关闭。它还可以减小框的宽度,以便更好地适应线宽。overlay. Then it remains the
of the text inside the circle. The example below compensates by using
\documentclass[10pt]{memoir}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds,patterns}
\tikzstyle{box} = [align=center, text width=\the\dimexpr\linewidth-10pt\relax,
draw=blue, fill=blue,
rectangle, rounded corners,
inner sep=5pt, inner ysep=5pt]
\begin{document}
\lipsum
~\\
\hspace*{-.3333em}%
\begin{tikzpicture}
\node[box](box){\color{white}\textbf{white text on blue background}};
\node[overlay,shape=circle,fill=white,inner sep=2mm] at (box.west) {};
\node[text=blue,right=-3pt] at (box.west) {\textbf{1}};
\end{tikzpicture}
~\\
\lipsum
\end{document}
答案3
嗯,它是实际上是垂直对齐的。例如,如果我们将圆圈涂成绿色,如下所示:
\begin{tikzpicture}
\node[box] (box){\color{white}\textbf{white text on blue background}};
\node[shape=circle,fill=green,inner sep=2mm] at (box.west) {};
\node[text=blue,right=-3pt] at (box.west) {\textbf{1}};
\draw [brown] (current bounding box.south west) rectangle
(current bounding box.north east);
\end{tikzpicture}
我们得到
所以我猜你想要的是将一些圆圈放在边界框外面,就像这样:
\begin{tikzpicture}
\node[box] (box){\color{white}\textbf{white text on blue background}};
\node[shape=circle,fill=white,inner sep=2mm] at (box.west) (circle) {};
\node[text=blue,right=-3pt] at (box.west) {\textbf{1}};
\pgfresetboundingbox
\useasboundingbox (circle.north) rectangle (box.south east);
\end{tikzpicture}
您可以从中获得