三个盒子并排 - tcolorbox

三个盒子并排 - tcolorbox

我想创建 3 个并排的框,如附件图片。请帮忙

我的代码:

%\documentclass[a4paper]{article}
\documentclass[a4paper]{book}
\usepackage{amsmath,amssymb}%      pour les maths
\usepackage{enumitem}
\usepackage{wrapfig}
\usepackage{graphicx}
\usepackage{MnSymbol,wasysym}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{framed}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage[utf8]{vietnam}
%\usepackage[utf8]{english}
\usepackage[english]{babel}
\usepackage[format=plain,
            labelfont={bf,it},
            textfont=it]{caption}

%\newcommand\captionof[2]{\def\@captype{#1}\caption}

\usepackage{tikzsymbols} 
\newtcbtheorem{myLemma}{Long text here without counter }{lemmastyle}{thm}

\usetikzlibrary{calc, fit, backgrounds}
\usepackage{varwidth}
\newcommand{\mybox}[4][\textwidth-\pgfkeysvalueof{/pgf/inner xsep}-2mm]{%
%\begin{figure}[!h]
\centering
\begin{tikzpicture}
\node[line width=0.5mm, inner ysep=10pt, text width=#1, outer sep=0] (text) {\begin{varwidth}{\textwidth}#4\end{varwidth}};
\node[text=white, above right, align=left] (title) at (text.north west) {#3};
\node[fit=(title) (text), line width=0.5mm, rounded corners, draw=#2, inner sep=0pt] (box){};
\begin{scope}[on background layer]
\fill[#2] (title.south west) -- (title.south east) to[out=0, in=180] ([xshift=1.5cm]title.east) -- (title.east-|box.north east) [rounded corners] -- (box.north east) -- (box.north west) [sharp corners] -- cycle;
\end{scope}
\end{tikzpicture} 
%\end{figure}
}

\usepackage{pifont}

\begin{document}

\tcbset{sidebyside,
  size=minimal,
  colback=white,
  lower separated=false,
  halign upper=flush center,
  halign lower=flush left,
  lefthand width=2.5cm, 
  frame empty,
}



\begin{tabular}{cccc}
\mybox[10cm]{green!70!black}{Eat That Frog | Related }{
\begin{enumerate}
\item ....................................................\hspace*{1cm}..........................

\item ....................................................\hspace*{1cm}..........................

\end{enumerate}
}
%\hspace*{1cm}
&
\mybox[3cm]{green!30!black}{Mood}{
 \hspace*{0.2cm} \dLaughey[2.0] \hspace*{0.5cm} \dNeutrey[2.0] \hspace*{0.5cm}  
 \\
 %\vspace*{1cm} \quad
%\vspace{0.2in}
 \hspace*{0.2cm} \dInnocey[2.0] \hspace*{0.5cm} \dWalley[2.0] \hspace*{0.5cm}
 }


\end{tabular}

\begin{tabular}{cccc}
\mybox[10cm]{blue!70!black}{ Appointments | When | With | Where}{
\begin{enumerate}
\item .....................................  .... : ....        .....................      ..................

\item .....................................  .... : ....        .....................      ..................

\end{enumerate}
}
&
\mybox[3cm]{green!30!black}{Drink up}{
 \hspace*{0.2cm} \bigcup \hspace*{0.2cm} \bigcup \hspace*{0.2cm}  \bigcup \hspace*{0.2cm}  \bigcup \hspace*{0.2cm}  \bigcup \hspace*{0.2cm}
 \\
 %\vspace*{1cm} \quad
%\vspace{0.2in}
 \hspace*{0.2cm} \bigcup \hspace*{0.2cm} \bigcup \hspace*{0.2cm}  \bigcup \hspace*{0.2cm}  \bigcup \hspace*{0.2cm}  \bigcup \hspace*{0.2cm}
 }
\end{tabular}



\end{document}

答案1

这用于\smash隐藏表格右侧框的高度。它基本上覆盖了第一行中缺失的单元格。

我使用 saveboxes 测量 tikzpictures 的高度(depths=0)。表格\arratystretch\dp\strutbox在两者之间添加。最后必须减去内部 xsep(乘以 2)和线宽才能得到所需的文本宽度。

顺便说一句,这些框对于页面来说太宽了。

%\documentclass[a4paper]{article}
\documentclass[a4paper]{book}
\usepackage{amsmath,amssymb}%      pour les maths
\usepackage{enumitem}
\usepackage{wrapfig}
\usepackage{graphicx}
\usepackage{MnSymbol,wasysym}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{framed}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage[utf8]{vietnam}
%\usepackage[utf8]{english}
\usepackage[english]{babel}
\usepackage[format=plain,
            labelfont={bf,it},
            textfont=it]{caption}

%\newcommand\captionof[2]{\def\@captype{#1}\caption}

\usepackage{tikzsymbols} 
\newtcbtheorem{myLemma}{Long text here without counter }{lemmastyle}{thm}

\usetikzlibrary{calc, fit, backgrounds}
\usepackage{varwidth}
\newcommand{\mybox}[4][\textwidth-\pgfkeysvalueof{/pgf/inner xsep}-2mm]{%
%\begin{figure}[!h]
\centering
\begin{tikzpicture}
\node[line width=0.5mm, inner ysep=10pt, text width=#1, outer sep=0] (text) {\begin{varwidth}{\textwidth}#4\end{varwidth}};
\node[text=white, above right, align=left] (title) at (text.north west) {#3};
\node[fit=(title) (text), line width=0.5mm, rounded corners, draw=#2, inner sep=0pt] (box){};
\begin{scope}[on background layer]
\fill[#2] (title.south west) -- (title.south east) to[out=0, in=180] ([xshift=1.5cm]title.east) -- (title.east-|box.north east) [rounded corners] -- (box.north east) -- (box.north west) [sharp corners] -- cycle;
\end{scope}
\end{tikzpicture}}

\usepackage{pifont}

\begin{document}

\tcbset{sidebyside,
  size=minimal,
  colback=white,
  lower separated=false,
  halign upper=flush center,
  halign lower=flush left,
  lefthand width=2.5cm, 
  frame empty,
}

\sbox0{\mybox[10cm]{green!70!black}{Eat That Frog | Related }{%
\begin{enumerate}
\item ....................................................\hspace*{1cm}..........................

\item ....................................................\hspace*{1cm}..........................

\end{enumerate}
}}%
\sbox1{\mybox[10cm]{blue!70!black}{ Appointments | When | With | Where}{
\begin{enumerate}
\item .....................................  .... : ....        .....................      ..................

\item .....................................  .... : ....        .....................      ..................

\end{enumerate}
}}%

\begin{tabular}{@{}cc@{}}
  \usebox0 & \\
  \usebox1 & \smash{\rotatebox[origin=bl]{90}{% 
  \mybox[\dimexpr \ht0+\ht1+\arraystretch\dp\strutbox-0.666em-0.5mm]% inner xsep=0.333em, linewidth=0.5mm (half in)
    {green!30!black}{Mood}{ \hspace*{0.2cm} \dLaughey[2.0] \hspace*{0.5cm} \dNeutrey[2.0] \hspace*{0.5cm} \\ %
    \vspace*{1cm} \quad %
    \vspace{0.2in} \hspace*{0.2cm} \dInnocey[2.0] \hspace*{0.5cm} \dWalley[2.0] }% 
}} 
\end{tabular} 


\end{document}

我不明白你为什么要使用 varwidth,除非它会占用枚举上方和下方的额外空间(如 minipage)。设置text width已将文本放入\parbox。我在这里替换了它,这样我就可以使用\hfil\centering

%\documentclass[a4paper]{article}
\documentclass[a4paper]{book}
\usepackage{amsmath,amssymb}%      pour les maths
\usepackage{enumitem}
\usepackage{wrapfig}
\usepackage{graphicx}
\usepackage{MnSymbol,wasysym}
\usepackage[svgnames]{xcolor}
\usepackage[most]{tcolorbox}
\usepackage{framed}
\usepackage{tikz}
\usepackage[utf8]{inputenc}
\usepackage[utf8]{vietnam}
%\usepackage[utf8]{english}
\usepackage[english]{babel}
\usepackage[format=plain,
            labelfont={bf,it},
            textfont=it]{caption}

%\newcommand\captionof[2]{\def\@captype{#1}\caption}

\usepackage{tikzsymbols} 
\newtcbtheorem{myLemma}{Long text here without counter }{lemmastyle}{thm}

\usetikzlibrary{calc, fit, backgrounds}
\usepackage{varwidth}
\newcommand{\mybox}[4][\dimexpr \textwidth-\pgfkeysvalueof{/pgf/inner xsep}-\pgfkeysvalueof{/pgf/inner xsep}-1mm]{%
%\begin{figure}[!h]
\centering
\begin{tikzpicture}
\node[line width=0.5mm, inner ysep=10pt, outer sep=0] (text) {\begin{minipage}{#1}#4\end{minipage}};
\node[text=white, above right, align=left] (title) at (text.north west) {#3};
\node[fit=(title) (text), line width=0.5mm, rounded corners, draw=#2, inner sep=0pt] (box){};
\begin{scope}[on background layer]
\fill[#2] (title.south west) -- (title.south east) to[out=0, in=180] ([xshift=1.5cm]title.east) -- (title.east-|box.north east) [rounded corners] -- (box.north east) -- (box.north west) [sharp corners] -- cycle;
\end{scope}
\end{tikzpicture}}

\usepackage{pifont}

\begin{document}

\tcbset{sidebyside,
  size=minimal,
  colback=white,
  lower separated=false,
  halign upper=flush center,
  halign lower=flush left,
  lefthand width=2.5cm, 
  frame empty,
}

\sbox0{\mybox[10cm]{green!70!black}{Eat That Frog | Related }{%
\begin{enumerate}
\item ....................................................\hspace*{1cm}..........................

\item ....................................................\hspace*{1cm}..........................

\end{enumerate}
}}%
\sbox1{\mybox[10cm]{blue!70!black}{ Appointments | When | With | Where}{
\begin{enumerate}
\item .....................................  .... : ....        .....................      ..................

\item .....................................  .... : ....        .....................      ..................

\end{enumerate}
}}%

\begin{tabular}{@{}cc@{}}
  \usebox0 & \\
  \usebox1 & \smash{\rotatebox[origin=bl]{90}{% 
  \mybox[\dimexpr \ht0+\ht1+\arraystretch\dp\strutbox-0.666em-0.5mm]% inner xsep=0.333em, linewidth=0.5mm (half in)
    {green!30!black}{Mood}{\centering \dLaughey[2.0] \hfil \dNeutrey[2.0] \hfil \dInnocey[2.0] \hfil \dWalley[2.0]}% 
}} 
\end{tabular} 


\end{document}

相关内容