如何对齐并自动调整 tcolorbox 宽度与 tikzpicture 内部或标题?

如何对齐并自动调整 tcolorbox 宽度与 tikzpicture 内部或标题?

我找不到让 tcolorbox 自动调整 tikzpictures 内部或标题(如果较宽)的方法。我还希望它们出现在同一条线

这是我的 MWE

\documentclass[a4paper,11pt]{article}
\usepackage[french]{babel}
 \usepackage[utf8]{inputenc}
 \usepackage[T1]{fontenc}
 \usepackage{tikz}
 \usepackage{tcolorbox}

\begin{document}




\newtcolorbox{blueboxb}[1]{hbox,center title, colback=pink!20, 
 colframe=blue!20,fonttitle=\bfseries,title={#1}}
\newtcolorbox{blueboxs}[1]{hbox,center title, colback=pink!20, 
 colframe=blue!20,fonttitle=\bfseries,title={#1}}
\newtcolorbox{orangebox}[1]{colback=pink!20,colframe=orange!40,fonttitle=\bfseries,
 title={#1}}

 \begin{blueboxb}{\color{black}{Droites parallèles}}
 \begin{tikzpicture}[scale=0.5]
 %1
 \begin{scope}
\draw (0,0) -- (5,0) -- (7,3) -- (2,3) -- cycle;
\draw[green!50!blue] (2,1) -- (4.5,2.5) node [right] {$\Delta$};
\draw[red!80,xshift=0.5cm,yshift=-0.5cm] (2,1) -- (4.5,2.5) node [right] 
{$\Delta^{\prime}$};
\end{scope}

%2
\begin{scope}[xshift=8cm]
\draw (0,0) -- (5,0) -- (7,3) -- (2,3) -- cycle;
\draw[red!80] (2,2.5) -- (5.5,1.5);
\draw[green!50!blue,dashed,thick] (2,2.5) -- (5.5,1.5) node [midway,above right] 
{$\Delta=\Delta^{\prime}$};
\end{scope}
\end{tikzpicture}
\end{blueboxb}
\begin{blueboxs}{\color{black}{Droites Confondues}}
 \begin{tikzpicture}[scale=0.5]
 \draw (0,0) -- (5,0) -- (7,3) -- (2,3) -- cycle;
 \draw[red!80] (2,2.5) -- (4.5,1) node [right] {$\Delta$};
 \draw[green!50!blue] (2,1) -- (4.5,2.5) node [right] {$\Delta^{\prime}$};
 \end{tikzpicture}
 \end{blueboxs}
 \begin{orangebox}{\color{black}{Droites Confondues}}
 \begin{tikzpicture}[scale=0.5]
 \draw (0,0) -- (5,0) -- (7,3) -- (2,3) -- cycle;
 \draw[thick,red!80] (2.5,4.5) node[black,right] {$\Delta^{\prime}$} -- (5,-0.5);
 \fill[pink!20] (4,0.1) rectangle (4.9,2);
 \draw[red!80,dashed] (2.5,4.5) -- (5,-0.5);
 \draw[green!50!blue] (0.5,0.4) node [right,black] {$\Delta$} -- (3,2.5);
 \end{tikzpicture}
 \end{orangebox}



\end{document}

谢谢你!

答案1

正如您在链接的答案中所看到的(有点隐藏,但是......)

  1. 关键字hbox使框具有内容的(水平)大小,并且
  2. 该开关抑制了盒子前后出现的nobeforeafter正常间距(请在手册中查找)。tcolorbox

添加此选项并显示页面框架,您将获得:

盒子

请注意\parident第一行的开头,事实上您没有hbox\ nobeforeafterpar orangebox, so it starts with something similar to\noindent`。

代码如下:

documentclass[a4paper,11pt]{article}
\usepackage[french]{babel}
 \usepackage[utf8]{inputenc}
 \usepackage[T1]{fontenc}
 \usepackage{tikz}
 \usepackage{tcolorbox}
 \usepackage[showframe]{geometry}

\begin{document}

\newtcolorbox{blueboxb}[1]{hbox,center title, colback=pink!20, 
 colframe=blue!20,fonttitle=\bfseries,title={#1},nobeforeafter}
\newtcolorbox{blueboxs}[1]{hbox,center title, colback=pink!20, 
 colframe=blue!20,fonttitle=\bfseries,title={#1},nobeforeafter}
\newtcolorbox{orangebox}[1]{colback=pink!20,colframe=orange!40,fonttitle=\bfseries, title={#1}}

 \begin{blueboxb}{\color{black}{Droites parallèles}}
 \begin{tikzpicture}[scale=0.5]
 %1
 \begin{scope}
\draw (0,0) -- (5,0) -- (7,3) -- (2,3) -- cycle;
\draw[green!50!blue] (2,1) -- (4.5,2.5) node [right] {$\Delta$};
\draw[red!80,xshift=0.5cm,yshift=-0.5cm] (2,1) -- (4.5,2.5) node [right] 
{$\Delta^{\prime}$};
\end{scope}
%2
\begin{scope}[xshift=8cm]
\draw (0,0) -- (5,0) -- (7,3) -- (2,3) -- cycle;
\draw[red!80] (2,2.5) -- (5.5,1.5);
\draw[green!50!blue,dashed,thick] (2,2.5) -- (5.5,1.5) node [midway,above right] 
{$\Delta=\Delta^{\prime}$};
\end{scope}
\end{tikzpicture}
\end{blueboxb}
\begin{blueboxs}{\color{black}{Droites Confondues}}
 \begin{tikzpicture}[scale=0.5]
 \draw (0,0) -- (5,0) -- (7,3) -- (2,3) -- cycle;
 \draw[red!80] (2,2.5) -- (4.5,1) node [right] {$\Delta$};
 \draw[green!50!blue] (2,1) -- (4.5,2.5) node [right] {$\Delta^{\prime}$};
 \end{tikzpicture}
 \end{blueboxs}
 \begin{orangebox}{\color{black}{Droites Confondues}}
 \begin{tikzpicture}[scale=0.5]
 \draw (0,0) -- (5,0) -- (7,3) -- (2,3) -- cycle;
 \draw[thick,red!80] (2.5,4.5) node[black,right] {$\Delta^{\prime}$} -- (5,-0.5);
 \fill[pink!20] (4,0.1) rectangle (4.9,2);
 \draw[red!80,dashed] (2.5,4.5) -- (5,-0.5);
 \draw[green!50!blue] (0.5,0.4) node [right,black] {$\Delta$} -- (3,2.5);
 \end{tikzpicture}
 \end{orangebox}
\end{document}

如果将hboxnobeforeafter添加到orangebox,则将得到:

满箱

...因为它们不适合排成一行。

相关内容