1

As a continue to this answer: https://tex.stackexchange.com/a/226751/29476
I want to know if there is an option to make something like this: enter image description here

That the title will be the section number and name and the body of the section will be at the body of the colorbox. Of course using titlesec:

\titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before-code>}[<after-code>]

This is possible?

Thank you!!

(P.S. If not tcolorbox - mdframed is OK)

3
  • 1
    Do you really want to use a "normal" section for this? That is going to be very troublesome as it's hard to detect the end of the section where you would need to insert the end of the colorbox. Maybe a dedicated environment would be more suitable?
    – TeXnician
    Commented Jul 25, 2018 at 8:46
  • @TeXnician - Great!! So can you tell me how to use it via environment?
    – heblyx
    Commented Jul 25, 2018 at 8:47
  • @TeXnician - Whats matter to me is that the section will be at the title and the body will be at the body of the box.
    – heblyx
    Commented Jul 25, 2018 at 8:49

1 Answer 1

4

This is an easy example with automatic addition to table of contents, nearly from the manual. As you can see you will also be able to mix ordinary sections with tcolorboxed sections.

Just to explain why your titlesec approach is very hard to implement: LaTeX (as opposed to ConTeXt) does not know the point a section really ends, so it cannot determine where the body of the environment should end. That's why this answer uses an explicit environment to work around this issue.

tcolorbox section

\documentclass{article}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\newtcolorbox[auto counter, use counter=section, list type=section, list inside=toc]{sectionbox}[1]{colback=red!5!white, colframe=red!75!black, fonttitle=\bfseries, title={\thetcbcounter\ #1}, list entry={\thetcbcounter\quad #1}, breakable}

\begin{document}
    \tableofcontents

    \begin{sectionbox}{Test}
        Test
    \end{sectionbox}
    \section{Test}
    \begin{sectionbox}{Test}
        Test
    \end{sectionbox}
\end{document}
6
  • Yes, but I asked for this format: \titleformat{<command>}[<shape>]{<format>}{<label>}{<sep>}{<before-code>}[<after-code>] - of titlesec....
    – heblyx
    Commented Jul 25, 2018 at 8:56
  • @heblyx I asked in the comment to your question whether a dedicated environment would be okay. See my edit for an explanation.
    – TeXnician
    Commented Jul 25, 2018 at 8:59
  • I see! The reason I ask it, it because I want to put it at a .layout file so I look for a generic code that I can drop from the paragraph styles menu (I'm using LyX). Can you help me with this?
    – heblyx
    Commented Jul 25, 2018 at 9:01
  • 1
    @heblyx Unfortunately not, because I'm not aware of any solution without an environment (the alternative with labels in the aux file would be very, very, very fragile and should probably not be used for productive editing, maybe just for finishing the layout).
    – TeXnician
    Commented Jul 25, 2018 at 9:09
  • @TeXnician I think you need to make sectionbox breakable.
    – Ignasi
    Commented Jul 25, 2018 at 10:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .