使用 \node 和 \tikz 时记事本错误

使用 \node 和 \tikz 时记事本错误

我想调整大小并从链接移动记事本:海报布局:背景和方框 并链接 更改记事本的宽度,高度

最小工作示例:

\documentclass{article}
\usepackage[most]{tcolorbox}
\usetikzlibrary{shadows,shapes.geometric}
\usepackage{lipsum}

\definecolor{mybrown}{RGB}{33,34,28}
\definecolor{myyellow}{RGB}{242,226,149}
\definecolor{mygreen}{RGB}{176,232,145}
\definecolor{myblue}{RGB}{61,139,189}
\definecolor{myorange}{RGB}{245,156,74}
\definecolor{mypurple}{RGB}{230,111,148}
\definecolor{myred}{RGB}{215,80,50}

\newtcolorbox{NotePad}[2][]{%
  enhanced,
  frame code=empty,
  boxsep=0.5cm,
  top=0.6cm,
  interior code={
  \fill[#2,drop shadow]
    (interior.south west) {[rounded corners=1.5cm]--
    (interior.south east)} --
    (interior.north east) --
    (interior.north west) --
    cycle;
  \fill[#2!80!black] 
    ([shift={(-0.9cm,0.5ex)}]interior.south east) to[out=30,in=-70]
    ([shift={(-0.55cm,0.7cm)}]interior.south east) to[out=-10,in=220]
    ([shift={(-0.7ex,0.9cm)}]interior.south east) to[out=250,in=30]
    cycle;  
  \fill[mybrown]
    ([yshift=-10pt]interior.north) circle [radius=0.23cm];
  \fill[mybrown!40]
    ([yshift=-10pt]interior.north) circle [radius=0.175cm];
  \node[
    cylinder,
    cylinder uses custom fill, 
    cylinder end fill=mybrown!60,
    cylinder body fill=mybrown,
    rotate=115,
    minimum width=9pt,
    minimum height=16pt
  ] 
  at ([shift={(-0.2pt,-9.8pt)}]interior.north) {};
  },
  #1
}



\begin{document}


%\column{.5\textwidth}
\tikz[overlay, remember picture] 
\node[anchor=south east,xshift=5.5cm, yshift=-3cm]
{
\begin{NotePad}[width=10cm,height =4cm]{myyellow}
Some test text for this block
\end{NotePad}
}
\tikz[overlay, remember picture] 
\node[anchor=south east,xshift=7.5cm, yshift=-10cm]
{
\begin{NotePad}[width=5cm,height=10cm]{myblue}
 test text 
\end{NotePad}
}

\end{document}

在此处输入图片描述

请查看附件,记事本的这个按钮显示错误。谢谢

答案1

tcbposter是 提供的一种环境tcolorbox,允许轻松放置和标注尺寸posterboxes。如果您可以使用 ,tcbposter您将避免与嵌套相关的问题tikzpictures

下面的代码展示了一个小例子。我把NotePad盒子转换成一种tcbset样式,并使用该样式来配置posterboxes。正如所见,posterbox尺寸可以根据海报网格或相对于其他盒子自动确定。

\documentclass{article}
\usepackage[most]{tcolorbox}
\usetikzlibrary{shadows,shapes.geometric}
\usepackage{lipsum}

\definecolor{mybrown}{RGB}{33,34,28}
\definecolor{myyellow}{RGB}{242,226,149}
\definecolor{mygreen}{RGB}{176,232,145}
\definecolor{myblue}{RGB}{61,139,189}
\definecolor{myorange}{RGB}{245,156,74}
\definecolor{mypurple}{RGB}{230,111,148}
\definecolor{myred}{RGB}{215,80,50}

\tcbset{
NotePad/.style={%
  enhanced,
  frame code=empty,
  boxsep=0.5cm,
  top=0.6cm,
  interior code={
  \fill[#1,drop shadow]
    (interior.south west) {[rounded corners=1.5cm]--
    (interior.south east)} --
    (interior.north east) --
    (interior.north west) --
    cycle;
  \fill[#1!80!black] 
    ([shift={(-0.9cm,0.5ex)}]interior.south east) to[out=30,in=-70]
    ([shift={(-0.55cm,0.7cm)}]interior.south east) to[out=-10,in=220]
    ([shift={(-0.7ex,0.9cm)}]interior.south east) to[out=250,in=30]
    cycle;  
  \fill[mybrown]
    ([yshift=-10pt]interior.north) circle [radius=0.23cm];
  \fill[mybrown!40]
    ([yshift=-10pt]interior.north) circle [radius=0.175cm];
  \node[
    cylinder,
    cylinder uses custom fill, 
    cylinder end fill=mybrown!60,
    cylinder body fill=mybrown,
    rotate=115,
    minimum width=9pt,
    minimum height=16pt
  ] 
  at ([shift={(-0.2pt,-9.8pt)}]interior.north) {};
  },
}}



\begin{document}
\begin{tcbposter}[%
    poster={columns=3, rows=3},
    ]
    \posterbox[NotePad=myyellow]{name=A, column=1, span=2}{Some test text for this block}
    \posterbox[NotePad=myblue]{name=B, column=3, rowspan=3}{Some test text for this block}
    \posterbox[NotePad=myorange]{name=C, between=A and bottom, span=2}{Some test text for this block}
    \posterbox[NotePad=mypurple]{column=2, row=2, span=1.5, rowspan=1.5}{Some test text for this block}
    \posterbox[NotePad=mygreen]{at=C.west, xshift=1cm, yshift=-2cm}{Some test text for this block}

\end{tcbposter}

\end{document}

在此处输入图片描述

答案2

不应该嵌套tikzpicture,但这就是你正在做的事情,因为tcolorbox它基于 TiZ. 解释如下此主题,您始终可以做的是将内部存储tikzpicture在中,然后在外部的节点中\savebox使用它。\saveboxtikzpicture

\documentclass{article}
\usepackage[most]{tcolorbox}
\usetikzlibrary{shadows,shapes.geometric}
\usepackage{lipsum}

\definecolor{mybrown}{RGB}{33,34,28}
\definecolor{myyellow}{RGB}{242,226,149}
\definecolor{mygreen}{RGB}{176,232,145}
\definecolor{myblue}{RGB}{61,139,189}
\definecolor{myorange}{RGB}{245,156,74}
\definecolor{mypurple}{RGB}{230,111,148}
\definecolor{myred}{RGB}{215,80,50}

\newtcolorbox{NotePad}[2][]{%
  enhanced,
  frame code=empty,
  boxsep=0.5cm,
  top=0.6cm,
  interior code={
  \fill[#2,drop shadow]
    (interior.south west) {[rounded corners=1.5cm]--
    (interior.south east)} --
    (interior.north east) --
    (interior.north west) --
    cycle;
  \fill[#2!80!black] 
    ([shift={(-0.9cm,0.5ex)}]interior.south east) to[out=30,in=-70]
    ([shift={(-0.55cm,0.7cm)}]interior.south east) to[out=-10,in=220]
    ([shift={(-0.7ex,0.9cm)}]interior.south east) to[out=250,in=30]
    cycle;  
  \fill[mybrown]
    ([yshift=-10pt]interior.north) circle [radius=0.23cm];
  \fill[mybrown!40]
    ([yshift=-10pt]interior.north) circle [radius=0.175cm];
  \node[
    cylinder,
    cylinder uses custom fill, 
    cylinder end fill=mybrown!60,
    cylinder body fill=mybrown,
    rotate=115,
    minimum width=9pt,
    minimum height=16pt
  ] 
  at ([shift={(-0.2pt,-9.8pt)}]interior.north) {};
  },
  #1
}


\newsavebox{\NPA}
\newsavebox{\NPB}

\begin{document}
\begin{lrbox}{\NPA}%
\begin{NotePad}[width=10cm,height =4cm]{myyellow}
Some test text for this block
\end{NotePad}%
\end{lrbox}%
\begin{lrbox}{\NPB}%
\begin{NotePad}[width=5cm,height=10cm]{myblue}
 test text 
\end{NotePad}%
\end{lrbox}%

%\column{.5\textwidth}
\tikz[overlay, remember picture]%
{\node[anchor=south east,xshift=5.5cm, yshift=-3cm]
{
\usebox\NPA
};}
\tikz[overlay, remember picture]%
{\node[anchor=south east,xshift=7.5cm, yshift=-10cm]
{
\usebox\NPB
};}

\end{document}

在此处输入图片描述

相关内容