删除用 tikz 制作的彩色框中的压痕

删除用 tikz 制作的彩色框中的压痕

我有一份如下所示的文档:

在此处输入图片描述

代码如下:

\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 theof 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}

您可以从中获得

正确的

相关内容