3

Writing a thesis (in french), I use many boxes to frame some date. Luckily, tcolor is quite powerful to make some nice ones. But I have a little problem with \tcbsubtitle to distinguish (or add with further informations) different data.

The title of the boxe is (nicely) integrated in the margin and I try to make the subtile do the same way... If somenone have an idea.

There is a MCE here:

\documentclass[12pt,french]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper]{geometry}
\usepackage{microtype}
\usepackage{graphicx}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage{xspace}
\xspaceremoveexception{-}
%\usepackage{varioref}
\usepackage[autostyle]{csquotes}
\usepackage{babel}
\usepackage[osf]{garamondx}
\usepackage[breaklinks,colorlinks=true]{hyperref}
%opening

\newenvironment{supercadre}[2]{
    \begin{tcolorbox}[enhanced,breakable,
        size=fbox,sharp corners=northwest,
        before=\smallskip,
        after=\smallskip,
        %   boxrule=5pt,
        parbox=true,
        adjusted title={\footnotesize{{#1} \no{#2}}},
        colframe=black,colback=black!01!white,  %couleur du cadre et du fond de la boît
        colbacktitle=black!10!white,            %couleur du fond du titre
        coltitle=black!50!black,                %couleur de la police du titre
        fonttitle=\bfseries,                    %font du titre
        subtitle style={colback=black!10!white},
        attach boxed title to top left={xshift=-\tcboxedtitlewidth,yshift=-\tcboxedtitleheight},
        boxed title style={size=fbox,sharp corners=east}
        ]}
    {\end{tcolorbox}}

\newcommand{\cadrebis}[3]{\begin{supercadre}{#1}{#2}\noindent{\small#3}\end{supercadre}}


\begin{document}


\cadrebis{Try}{1}{
    \lipsum[2]
    \tcbline
    \lipsum[1]
}

\cadrebis{Try}{2}{
    \lipsum[2]
    \tcbsubtitle[nobeforeafter,subtitle style={colbacktitle=white, attach boxed title to top left={xshift=-\tcboxedtitlewidth,yshift=-\tcboxedtitleheight}}]{The subtitle}
    \lipsum[2]
}

\end{document}
0
2

If your boxes only contain one subtitle you could use something like following code. It uses segmentation position to attach an optional overlayed tcbox with subtitle contents.

\documentclass[12pt,french]{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[a4paper]{geometry}
%\usepackage{microtype}
%\usepackage{graphicx}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
%\usepackage{xspace}
%\xspaceremoveexception{-}
%\usepackage{varioref}
%\usepackage[autostyle]{csquotes}
\usepackage{babel}
%\usepackage[osf]{garamondx}
\usepackage[breaklinks,colorlinks=true]{hyperref}
%opening

\newtcolorbox{supercadre}[3][]{%
    enhanced,breakable,
   size=fbox,sharp corners=northwest,
   before=\smallskip,
   after=\smallskip,
%  boxrule=5pt,
   parbox=true,
   adjusted title={\footnotesize{{#2} \no{#3}}},
   colframe=black,colback=black!01!white,  %couleur du cadre et du fond de la boît
   colbacktitle=black!10!white,            %couleur du fond du titre
   coltitle=black!50!black,                %couleur de la police du titre
   fonttitle=\bfseries,                    %font du titre
   fontupper=\small,
   fontlower=\small,
   subtitle style={colback=black!10!white},
   attach boxed title to top left={xshift=-\tcboxedtitlewidth,yshift=-\tcboxedtitleheight},
   boxed title style={size=fbox,sharp corners=east},
   #1
}

\newtcbox{\subtitle}{size=fbox, sharp corners=east, colback=black!10!white, fontupper=\bfseries, colframe=black}

\tcbset{subtitle/.style={overlay={\node[anchor=north east, inner sep=0pt] at (segmentation.west) {\subtitle{#1}};}}}
\newcommand{\cadrebis}[3]{\begin{supercadre}{#1}{#2}#3\end{supercadre}}


\begin{document}

\begin{supercadre}[subtitle=SubTitle]{Try}{1}
\lipsum[2]
\tcblower
\lipsum[1]
\end{supercadre}

\begin{supercadre}[subtitle=Test]{Try}{1}
\lipsum[2]
\tcblower
\lipsum[1]
\end{supercadre}

\end{document}

enter image description here

Update

Another option coulb be to mimmic one tcolorbox with several tcolorboxes without vertical space between them. Following solution is steel not perfect (I don't know why separation line introduces undesired space), but you can start to work with it:

\documentclass[12pt,french]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}


\tcbset{
    general/.style={
        enhanced,
        breakable,
        colback=black!1!white,
        colbacktitle=black!10!white,
        coltitle=black,
        fonttitle=\bfseries,
        fontupper=\small,
        size=fbox,
        parbox=true,
        attach boxed title to top left={xshift=-\tcboxedtitlewidth, yshift=-\tcboxedtitleheight},
        boxed title style={size=fbox, sharp corners=east}
        }
}

\newtcolorbox{topbox}[3][]{%
    general,
    bottomrule=0pt,
    after=\par\nointerlineskip,
    before={},
    sharp corners,
    adjusted title={\footnotesize{{#2} \no{#3}}},
    rounded corners=northeast,#1}

\newtcolorbox{middlebox}[3][]{%
    general,
    bottomrule=0pt,
    toprule=0pt,
    after=\par\nointerlineskip,
    before={},
    sharp corners,
    overlay={\draw[dashed](frame.north west)--(frame.north east);},
    adjusted title={\footnotesize{{#2} \no{#3}}},
    #1
    }

\newtcolorbox{bottombox}[3][]{%
    general,
    toprule=0pt,
    before={},
    sharp corners=north,
    overlay={\draw[dashed](frame.north west)--(frame.north east);},
    adjusted title={\footnotesize{{#2} \no{#3}}},
    #1
    }

\begin{document}
\begin{topbox}{1}{test}
\lipsum[1]
\end{topbox}
\begin{middlebox}{2}{test}
\lipsum[1]
\end{middlebox}
\begin{bottombox}{3}{test}
\lipsum[1]
\end{bottombox}
\end{document}

enter image description here

4
  • It is indeed a functional solution. Unfortunately, I use subtitles in a box several times... :-( (but I will try to do somthing with)
    – tignous
    Nov 8 '18 at 16:53
  • @tignous May be the second solution is better for you. I hope so!
    – Ignasi
    Nov 8 '18 at 20:49
  • 1
    Yep, that will work and another user do a solution with raster and tcbitem which is kind of the same way. Many thanks for the help.
    – tignous
    Nov 9 '18 at 18:16
  • 1
    @tignous Yes, it's possible to do it with tcbraster, but in this case internal boxes are not breakable. With independent boxes, they can break without problems.
    – Ignasi
    Nov 9 '18 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.