So rücken Sie nur die erste Zeile in tcolorbox ein

So rücken Sie nur die erste Zeile in tcolorbox ein

Wie kann ich nur die erste Zeile einrücken tcolorbox?

\documentclass[12pt,a4paper]{book}
\usepackage[listings,many]{tcolorbox}
\usetikzlibrary{calc}
\usepackage{lipsum}

\tcbuselibrary{listingsutf8,breakable,skins}
\tcbset{listing engine=listings}
\tcbset{mystyle/.style={
  breakable,
  enhanced,
  rightrule=0pt,
  toprule=0pt,
  outer arc=0pt,
  before upper={\parindent17pt},
parbox = true,
  arc=0pt,
  colback=white,
  attach boxed title to top left,
  fonttitle=\sffamily
  }
}
\newtcolorbox[auto counter]{mybox}[1][]{
  mystyle,colframe=black,boxed title style={
    colback=black,
    outer arc=0pt,
    arc=0pt,
    top=0pt,
    bottom=0pt,
left=1pt,
right=1pt
    },
left=0pt,right=0pt,top=-18pt,bottom=0pt, 
  title=\thetcbcounter,
  overlay unbroken and first={
      \path
        let
        \p1=(title.north west),
        \p2=(frame.north west)
        in
        node[anchor=west,font=\sffamily,text width=\x2-\x1]
        at (title.west) {#1};
  }
}
\begin{document}


\begin{mybox}
\lipsum[1-8]
\end{mybox}

\end{document}

Bildbeschreibung hier eingeben

Antwort1

Sie haben den Wert \parindentauf festgelegt 17pt, möchten damit aber eigentlich nur Platz für das nummerierte Titelfeld schaffen. Sie benötigen also wirklich \parindent=0ptund dann einen manuellen Einzug im ersten Absatz.

Dies erreichen Sie mit:

before upper={\setlength{\parindent}{0pt}\hspace*{17pt}}

Hier ist ein vollständiges Beispiel:

\documentclass[12pt,a4paper]{book}
\usepackage[listings,many]{tcolorbox}
\usetikzlibrary{calc}
\usepackage{lipsum}

\tcbuselibrary{listingsutf8,breakable,skins}
\tcbset{listing engine=listings}
\tcbset{mystyle/.style={
  breakable,
  enhanced,
  rightrule=0pt,
  toprule=0pt,
  outer arc=0pt,
  before upper={\setlength{\parindent}{0pt}\hspace*{17pt}},
parbox = true,
  arc=0pt,
  colback=white,
  attach boxed title to top left,
  fonttitle=\sffamily
  }
}
\newtcolorbox[auto counter]{mybox}[1][]{
  mystyle,colframe=black,boxed title style={
    colback=black,
    outer arc=0pt,
    arc=0pt,
    top=0pt,
    bottom=0pt,
left=1pt,
right=1pt
    },
left=0pt,right=0pt,top=-18pt,bottom=0pt, 
  title=\thetcbcounter,
  overlay unbroken and first={
      \path
        let
        \p1=(title.north west),
        \p2=(frame.north west)
        in
        node[anchor=west,font=\sffamily,text width=\x2-\x1]
        at (title.west) {#1};
  }
}
\begin{document}


\begin{mybox}
\lipsum[1-2]
\end{mybox}

\end{document}

Ausgabe des Codes

verwandte Informationen