tikz로 수정된 섹션 제목에서는 줄바꿈이 작동하지 않습니다.

tikz로 수정된 섹션 제목에서는 줄바꿈이 작동하지 않습니다.

긴 하위/섹션 제목에 문제가 있습니다. \\연결되지 않습니다.

저는 Latex를 처음 사용하기 때문에 이 아름다운 템플릿을 채택했습니다.http://www.fluortools.com/misc/LaTeXtemplate내 필요에 맞게 수정했습니다.

그러나 지금은 하위/섹션 제목에 줄 바꿈이 붙어 있습니다.

MWE는 다음과 같습니다.

\documentclass[a4paper,12pt,oneside]{scrbook}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[scaled]{berasans}
\usepackage[scaled]{beramono} 
 \usepackage[english]{babel}
\usepackage[left=3cm,right=3cm,top=2.5cm,bottom=3cm,includehead,headheight=13.6pt]{geometry}
\usepackage{titlesec}
\usepackage{tikz}
\usetikzlibrary{calc,decorations,decorations.pathmorphing,arrows,matrix,positioning,patterns}
\usepackage{xcolor}
\selectcolormodel{cmyk}
 \newcommand\boxedSection[3]{{%
%
     \begin{tikzpicture}[inner sep=#3,line width=1.0pt]
         \node[anchor=east,rectangle,draw] at (0,0) (counter) {\textbf{#2}};
             \draw (counter.south west)  ++(.0pt,.5pt)-- ++($(\linewidth,0) - (2.5pt,0)$);
\node [right of=counter,anchor=west]{#1};
     \end{tikzpicture}
 }}
 \newcommand\boxedSectionB[3]{{%
%
     \begin{tikzpicture}[inner sep=#3,line width=1pt]
         \node[anchor=east,rectangle,draw,fill=black] at (0,0) (counter) {\color{white}\textbf{#2}};
             \draw (counter.south west) ++(.0pt,.5pt)-- ++($(\linewidth,0) - (2.5pt,0)$);
\node [right of=counter,anchor=west]{#1};
     \end{tikzpicture}
 }}
\newcommand\boxedsection[1]{\boxedSectionB{#1}{\thesection}{2mm}}
\newcommand\boxedsubsection[1]{\boxedSection{#1}{\thesubsection}{1.7mm}}
\newcommand\boxedsubsubsection[1]{\boxedSection{#1}{\thesubsubsection}{1.5mm}}
 \titleformat{\section}[hang]%
     {\usekomafont{section}}%
     {}%
     {.0em}%
     {\filright\boxedsection}%

 \titleformat{\subsection}[hang]%
     {\usekomafont{subsection}}%
     {}%
     {.0em}%
     {\filright\boxedsubsection}%

 \titleformat{\subsubsection}[hang]%
     {\usekomafont{subsubsection}}%
     {}%
     {.0em}%
     {\filright\boxedsubsubsection}%

\titlespacing{\section}{0pt}{1.5cm}{-1cm}
\titlespacing{\subsection}{0pt}{1.5cm}{-1cm}
\titlespacing{\subsubsection}{0pt}{6pt}{6pt}
\titlespacing{\paragraph}{}{0pt}{0pt}


\begin{document}

\subsection{This title is really really really long so I'd liked to have a \\line break but instead is just go on and on ...}

\end{document}

titleformat에서 boxedSection 부분을 제거하자마자 linebreak가 \\다시 작동하지만 물론 멋진 레이아웃도 제거됩니다.

줄 바꿈이 다시 작동하지만 멋진 레이아웃이 유지되도록 누군가 MWE를 수정해 주실 수 있나요?

정말 감사합니다!!

미슈코

편집하다 그래서 내 목적에 잘 맞는 솔루션을 찾았습니다. touhami가 제안한 대로 boxedSectionB를 변경하지 않고 text width=13cm그대로 anchor=west 두고 boxedSection에 줄을 추가하고 제거했습니다. 따라서 코드는 다음과 같습니다.

     \newcommand\boxedSection[3]{{%
%
     \begin{tikzpicture}[inner sep=#3,line width=1.0pt]
         \node[anchor=east,rectangle,draw] at (0,0) (counter) {\textbf{#2}};   
\node [right of=counter,anchor=west,text width=13cm]{#1};
     \end{tikzpicture}
 }}

결과는 다음과 같습니다. 여기에 이미지 설명을 입력하세요

답변1

업데이트

package 가 없는 또 다른 제안이 있습니다 titlesec. 이제 제목 아래에는 규칙이 없습니다.

\documentclass[a4paper,12pt,oneside]{scrbook}[2015/10/03]

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[scaled]{berasans}
\usepackage[scaled]{beramono} 
 \usepackage[english]{babel}
\usepackage[margin=3cm,top=2.5cm,includehead,headheight=13.6pt]{geometry}
\usepackage{xcolor}

\setcounter{secnumdepth}{\subsubsectionnumdepth}% subsubsection numbered

\RedeclareSectionCommands[
  font=\normalsize,
  %indent=-1em
]{section,subsection,subsubsection}

\newcommand*\BoxedSectionNumber[2]{{%
  \setlength\fboxrule{1pt}%
  \setlength\fboxsep{#2}%
  \ifstr{#1}{section}{%
    \colorbox{darkgray}{\textcolor{white}{\csname the#1\endcsname}}%
  }{\fbox{\csname the#1\endcsname}}%
  \hspace*{2\fboxsep}%
}}

\renewcommand*\sectionformat{\BoxedSectionNumber{section}{2mm}}
\renewcommand*\subsectionformat{\BoxedSectionNumber{subsection}{1.7mm}}
\renewcommand*\subsubsectionformat{\BoxedSectionNumber{subsection}{1.5mm}}

\newsavebox\SectionNumberBox

\renewcommand*\sectionlinesformat[4]{%
  \sbox{\SectionNumberBox}{\hspace*{#2}#3}%
  \noindent\usebox\SectionNumberBox%
  \parbox{\dimexpr\textwidth-\wd\SectionNumberBox\relax}{#4}%
  \par\nobreak%
}

\usepackage{blindtext}% dummy text

\begin{document}
\section{Section title}
\blindtext

\subsection{This title is really really really long so I'd liked
      to have a line break but instead is just go on and on ...}
\blindtext
\subsubsection{Subsubsection title}
\blindtext
\end{document}

결과:

여기에 이미지 설명을 입력하세요

주석을 해제하면 indent=-1em얻을 수 있습니다.

여기에 이미지 설명을 입력하세요


원래 답변

titlesecKOMA-Script 클래스와 함께 패키지를 사용하는 것은 권장되지 않습니다. KOMA-Script 및 titlesec.

다음은 KOMA-Script 버전 3.19a(현재 CTAN) 이상이 필요한 titlesec제안 입니다 .tikz

\documentclass[a4paper,12pt,oneside]{scrbook}[2015/10/03]

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[bitstream-charter]{mathdesign}
\usepackage[scaled]{berasans}
\usepackage[scaled]{beramono} 
 \usepackage[english]{babel}
\usepackage[left=3cm,right=3cm,top=2.5cm,bottom=3cm,includehead,headheight=13.6pt]{geometry}
\usepackage{xcolor}

\setcounter{secnumdepth}{\subsubsectionnumdepth}% subsubsection numbered

\RedeclareSectionCommands[font=\normalfont]{section,subsection,subsubsection}
\RedeclareSectionCommands[
  beforeskip=-1.5cm,
  afterskip=1cm,
  font=\normalfont
]{section,subsection}
\RedeclareSectionCommand[
  beforeskip=-12pt,
  afterskip=6pt,
  font=\normalfont
]{subsubsection}

\newcommand*\sectionnumberfboxsep{2mm}
\newcommand*\subsectionnumberfboxsep{1.7mm}
\newcommand*\subsubsectionnumberfboxsep{1.5mm}

\renewcommand*\sectionformat{{%
  \setlength\fboxsep{\sectionnumberfboxsep}%
  \setlength\fboxrule{1pt}%
  \colorbox{black}{\bfseries\textcolor{white}{\thesection}}%
}}
\renewcommand*\subsectionformat{{%
  \setlength\fboxsep{\subsectionnumberfboxsep}%
  \setlength\fboxrule{1pt}%
  \fbox{\bfseries\thesubsection}%
}}
\renewcommand*\subsubsectionformat{{%
  \setlength\fboxsep{\subsubsectionnumberfboxsep}%
  \setlength\fboxrule{1pt}%
  \fbox{\bfseries\thesubsubsection}%
}}
\makeatletter
\renewcommand*\sectionlinesformat[4]{%
  \ifstr{#1}{section}{%
    \leavevmode\rlap{\rule[\dimexpr-\sectionnumberfboxsep-1pt\relax]{\textwidth}{1pt}}%
    \parbox[b]{3em}{#3}\parbox[b]{\dimexpr\textwidth-3em}{#4}\par\nobreak%
  }{%
  \ifstr{#1}{subsection}{%
    \leavevmode\rlap{\rule[\dimexpr-\subsectionnumberfboxsep-1pt\relax]{\textwidth}{1pt}}%
    \parbox[b]{4em}{#3}\parbox[b]{\dimexpr\textwidth-4em}{#4}\par\nobreak%
  }{%
  \ifstr{#1}{subsubsection}{%
    \leavevmode\rlap{\rule[\dimexpr-\subsubsectionnumberfboxsep-1pt\relax]{\textwidth}{1pt}}%
    \parbox[b]{4.75em}{#3}\parbox[b]{\dimexpr\textwidth-4.75em}{#4}\par\nobreak%
  }{%
    \@hangfrom{\hspace*{#2}#3}{#4}%
  }}}%
}
\makeatletter

\usepackage{blindtext}% dummy text

\begin{document}
\section{Section title}
\blindtext
\subsection{This title is really really really long so I'd liked to have a line break but instead is just go on and on ...}
\blindtext
\subsubsection{Subsubsection title}
\blindtext
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보