1

When I create boxes with tcolorbox, I get an unwanted indentation in two places: once directly before the heading and secondly in place of the first paragraph (all the following paragraphs have no indentation as wanted).

enter image description here

I wrap each colorbox into a note environment and its parts into separate field environments to be able to parse the .tex-file later and import it into Anki.

The code for the definition of the colorboxes/environments:

\usepackage[skins, most]{tcolorbox}
\usepackage{titlesec}
\usepackage{xifthen}

\tcbset{default/.style={
            enhanced,
            breakable,
            arc=0pt,
            outer arc=0pt,
            frame hidden,
            fontupper=\normalsize\bfseries\boldmath,
            fontlower=\small,
            coltext=mediumgray!50!black,
            colback=mediumgray!20,
            parbox=false,
            segmentation hidden,
            grow to left by=-0.5cm,
            grow to right by=-0.5cm,
        }
}

\tcbset{definition/.style={default,
            coltext=grapefruit!50!black,
            colback=grapefruit!25
        }
}

\newcounter{notefield}
\newenvironment{note}[1][default]
{
    \titleformat*{\section}{\small\bfseries}
    \titleformat*{\subsection}{\small\bfseries}
    \titleformat*{\subsubsection}{\small\bfseries}

    \setcounter{notefield}{0}
    \begin{tcolorbox}[#1]
        }
        {
    \end{tcolorbox}
}

\newenvironment{field}{}{}

\BeforeBeginEnvironment{field}{
    \stepcounter{notefield}
    \ifnum\value{notefield}=2
        \tcblower
    \fi
}

The code to generate a box:

\begin{note}[definition]
    \begin{field}
        Def.: Körper
    \end{field}
    \begin{field}
        Ein kommutativer unitärer Ring, der nicht der Nullring ist, ist ein Körper, wenn in ihm jedes von Null verschiedene Element ein Inverses bezüglich der Multiplikation besitzt.
    \end{field}
\end{note}

I use the package parskip (with the configuration parfill) to suppress indentations and I assume that it may conflict with tcolorboxes.

1
  • 3
    Please don't post code fragments. Always make a small, but compilable text file, including a class and a document environment. May 29 at 14:35

1 Answer 1

2

You have a truckload of unprotected line endings in your definitions, which will act like a space:

\documentclass{article}

\usepackage[skins, most]{tcolorbox}
\usepackage{titlesec}
\usepackage{xifthen}

\tcbset{default/.style={
            enhanced,
            breakable,
            arc=0pt,
            outer arc=0pt,
            frame hidden,
            fontupper=\normalsize\bfseries\boldmath,
            fontlower=\small,
            coltext=gray!50!black,
            colback=gray!20,
            parbox=false,
            segmentation hidden,
            grow to left by=-0.5cm,
            grow to right by=-0.5cm,
        }
}

\tcbset{definition/.style={default,
            coltext=green!50!black,
            colback=green!25
        }
}

\newcounter{notefield}
\newenvironment{note}[1][default]
{%
    \titleformat*{\section}{\small\bfseries}%
    \titleformat*{\subsection}{\small\bfseries}%
    \titleformat*{\subsubsection}{\small\bfseries}%
%
    \setcounter{notefield}{0}%
    \begin{tcolorbox}[#1]%
        }
        {%
    \end{tcolorbox}%
}

\newenvironment{field}{}{}

\BeforeBeginEnvironment{field}{%
    \stepcounter{notefield}%
    \ifnum\value{notefield}=2
        \tcblower%
    \fi%
}

\begin{document}

\begin{note}[definition]
    \begin{field}%
        Def.: Körper
    \end{field}%
    \begin{field}%
        Ein kommutativer unitärer Ring, der nicht der Nullring ist, ist ein Körper, wenn in ihm jedes von Null verschiedene Element ein Inverses bezüglich der Multiplikation besitzt.
    \end{field}%
\end{note}

\end{document}

enter image description here

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