使用 tcolorbox 和 tikz

使用 tcolorbox 和 tikz

我想tcolorbox一起使用。需要一些用箭头连接的tikz节点 。tcolorbox

\documentclass[border=10pt]{standalone}

\usepackage{enumitem}
\setlist[itemize]{leftmargin=*, itemsep = 0em}
\usepackage[none]{hyphenat}

\usepackage{tikz}
\usetikzlibrary{matrix, shapes, arrows, positioning}

\usepackage[most]{tcolorbox}

\begin{document}


\newtcolorbox{GreenBox}[1]{colback = green!5!white,
colframe = green!75!black, arc = 4mm, outer arc = 1mm, fonttitle = \huge\textbf, title = #1}


\begin{GreenBox}{\textit{ASD}}


\begin{tikzpicture}

\node [text width = 6cm] at (0, 0) (node1) {
   \begin{GreenBox}{\textit{AS}}
   \begin{itemize}
   \item A
   \item B
   \end{itemize}
   \end{GreenBox}
   };

\node [text width = 6cm, right of = node1]  (node2) {
   \begin{GreenBox}{\textit{ASD}}
   \begin{itemize}
   \item AS
   \item BC
   \end{itemize}
   \end{GreenBox}
   }

%\node at (0,0) (node1) [shape=rectangle,fill=green] {box1}

\end{tikzpicture}

\end{GreenBox}

\end{document}

答案1

tcolorboxenhanced稍后可以remember(ed) as在 中引用带有皮肤的 。这样,除非需要在框之间进行特殊定位,否则tikzpicture就不需要tcolorbox在 中引用 。TikZ node

以下代码显示了 OP 代码的一个示例。GreenBox定义已被更改为接受可选参数并使框标题成为强制性的。

\documentclass[border=10pt]{standalone}

\usepackage{enumitem}
\setlist[itemize]{leftmargin=*, itemsep = 0em}
\usepackage[none]{hyphenat}

\usepackage{tikz}
\usetikzlibrary{matrix, shapes, arrows, positioning}

\usepackage[most]{tcolorbox}

\begin{document}


\newtcolorbox{GreenBox}[2][]{%
    enhanced,
    colback = green!5!white,
    colframe = green!75!black, 
    arc = 4mm, outer arc = 1mm, 
    fonttitle = \huge\slshape\textbf, 
    title = #2,
    #1}

\begin{GreenBox}{ASD}
   \begin{GreenBox}[width=5cm, remember as=box1, nobeforeafter]{AS}
   \begin{itemize}
   \item A
   \item B->
   \end{itemize}
   \end{GreenBox}
   \hfill
   \begin{GreenBox}[width=5cm, remember as=box2, nobeforeafter]{ASD}
   \begin{itemize}
   \item AS
   \item BC
   \end{itemize}
   \end{GreenBox}
\end{GreenBox}

\begin{tikzpicture}[overlay, remember picture, line width=1mm, draw=red]
\draw[->] (box1)--(box2);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容