Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I would like to wrap the section. How can I do it?

enter image description here

The following code is my MWE.

\documentclass[b5paper,10pt,twoside,parskip=half,numbers=noenddot,bibliography=totoc]{scrbook}
%bibliography=totocnumbered numera la bibliografia

\newcommand{\Aref}[1]{Appendix  \ref{#1}} %\thechapter
\def\chapterautorefname{Chapter}
\usepackage{xspace}

%\usepackage[cam,a4,center,pdftex]{crop} %for markings
\usepackage[squaren]{SIunits} % provide \micro command
\usepackage{amsmath,amssymb}             % AMS Math
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{units} % nicefrac
\usepackage[italian]{babel} %modifica cesare
\usepackage{eurosym}
\usepackage{booktabs}
%\usepackage{csquotes}
%\usepackage[protrusion=true,expansion]{microtype}backend=biber,
%\usepackage[style=numeric-comp,citestyle=numeric-comp,bibstyle=numeric-short,sorting=none,natbib=true,backref=true,hyperref=true,autocite=superscript,maxnames=99,maxcitenames=2,isbn=false,url=false,eprint=false,firstinits=true,mcite,subentry]{biblatex}
%\usepackage[final]{microtype}
%\usepackage[superscript]{cite}%modifica cesare
\usepackage{microtype}
\usepackage{enumerate}
\usepackage{graphicx}
\usepackage{subfig}
%\usepackage[danish]{babel}
\usepackage{latexsym,amssymb,amsmath,verbatim}
\usepackage{array,booktabs}
\usepackage{placeins}
 \let\oldsection=\section % gemmer den gamle definition
 \renewcommand\section{\FloatBarrier\oldsection}
\usepackage{caption}
 \captionsetup{font=small,labelfont=bf}
%\usepackage{cite}
%\usepackage{hyperref}

%\DeclareFieldFormat{volcitevolume}{\bibstring{volume}\ppspace\RN{#1}}
%\AtEveryCitekey{\clearfield{institude}}
%\renewcommand{\cite}{\supercite}
%\renewcommand{\citep}{\supercite}
%\renewcommand{\citet}[2][]{\citeauthor{#2}\supercite{#2}\ifstrempty{#1}{}{, #1}}
% \DeclareFieldFormat{bibentrysetcount}{\newline(\mknumalph{#1})\addhighpenspace}
\usepackage{makeidx}
\usepackage{longtable}
\usepackage{calc}
%\usepackage{etoolbox}
\usepackage{leftidx}
\makeindex

\usepackage{booktabs}
\setlength{\heavyrulewidth}{1.2pt}
\usepackage{pdfpages}
\usepackage[left=3.15cm,right=2.55cm,top=1.8cm,bottom=0.89cm,includefoot,includehead,headheight=13.6pt]{geometry}
\usepackage{setspace}
\setstretch{1.1}
\usepackage[nottoc, notlof, notlot]{tocbibind}
\usepackage[nohints]{minitoc}
\setcounter{minitocdepth}{2}


\mtcindent=15pt
\renewcommand{\ptcfont}{\small\rm}
\renewcommand{\ptcCfont}{\small\bm}
\renewcommand{\ptcSfont}{\small\rm}
\renewcommand{\ptcSSfont}{\footnotesize\rm}
\renewcommand{\ptcSSSfont}{\footnotesize\rm}
% Use \minitoc where to put a table of contents
%\usepackage{cm-super}
\RequirePackage{fix-cm}

\usepackage{type1cm}
\usepackage{titlesec}

\usepackage{aecompl}
\usepackage{xargs}
% Glossary / list of abbreviations

\usepackage[intoc]{nomencl}
\renewcommand{\nomname}{List of Abbreviations}
%makeindex Thesis.nlo -o Thesis.nls

\makenomenclature
\usepackage{pgf}%,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade}
\usepackage{tikz}
\usetikzlibrary{calc,decorations,decorations.pathmorphing,arrows,matrix,positioning,patterns}
\usepackage[version=3]{mhchem}% use \ce for chemistry
\usepackage{array}

% My pdf code


\usepackage{graphicx}
\DeclareGraphicsExtensions{.jpg}
\DeclareGraphicsExtensions{.pdf}

\graphicspath{{.}{images/}}

% Links in pdf
\usepackage{xcolor}
\selectcolormodel{cmyk}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{2}

% Some useful commands and shortcut for maths:  partial derivative and stuff

\newcommand{\pd}[2]{\frac{\partial #1}{\partial #2}}
\def\abs{\operatorname{abs}}
\def\argmax{\operatornamewithlimits{arg\,max}}
\def\argmin{\operatornamewithlimits{arg\,min}}
\def\diag{\operatorname{Diag}}
\newcommand{\eqRef}[1]{(\ref{#1})}

\titlespacing*{\chapter}{0cm}{-1.cm}{-40pt}%pbk
%\titleformat{\chapter}[display]{\Huge\filleft\scshape}{ \normalfont\bf\fontfamily{put}\fontseries{b}\fontsize{95pt}{0pt}\selectfont\thechapter}{20pt}{}[\titlerule\vspace{2ex}\filright\vspace{2ex}]

%\titleformat{\section}[block]
%{\normalfont\sffamily}
%{\thesection}{.5em}{\titlerule\\[.8ex]\bfseries}


\titlespacing*{\part}{-10pt}{120pt}{-80pt}%pbk
\titleformat{\part}[frame]{\Huge\filcenter\scshape}{ \normalfont\bf\fontsize{85pt}{0pt}\selectfont \raisebox{1.7cm}{ Part\fontfamily{put}\fontseries{b}\fontsize{105pt}{0pt}\selectfont \hspace{.2em}\thepart} }{30pt}{}[\filright]

 \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}%




\usepackage{rotating}
\usepackage{fancyhdr}                    % Fancy Header and Footer

% \usepackage{txfonts}                     % Public Times New Roman text & math font

%%% Fancy Header %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Fancy Header Style Options

\pagestyle{fancy}                       % Sets fancy header and footer
\fancyfoot{}                            % Delete current footer settings

%\renewcommand{\chaptermark}[1]{         % Lower Case Chapter marker style
%  \markboth{\chaptername\ \thechapter.\ #1}}{}} %

%\renewcommand{\sectionmark}[1]{         % Lower case Section marker style
%  \markright{\thesection.\ #1}}         %

\fancyhead[LE,RO]{\bfseries\thepage}    % Page number (boldface) in left on even
% pages and right on odd pages
\renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{\thechapter.\ #1}}{}}
\fancyhead[RE]{\bfseries\nouppercase{\leftmark}}      % Chapter in the right on even pages
\fancyhead[LO]{\bfseries\nouppercase{\rightmark}}     % Section in the left on odd pages

\let\headruleORIG\headrule
\renewcommand{\headrule}{\color{black} \headruleORIG}
\renewcommand{\headrulewidth}{1.0pt}
\usepackage{colortbl}
\arrayrulecolor{black}

\fancypagestyle{plain}{
  \fancyhead{}
  \fancyfoot{}
  \renewcommand{\headrulewidth}{0pt}
}

\usepackage{algorithm}
\usepackage[noend]{algorithmic}


%%% Clear Header %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Clear Header Style on the Last Empty Odd pages
\makeatletter

\def\cleardoublepage{\clearpage\if@twoside \ifodd\c@page\else%
  \hbox{}%
  \thispagestyle{empty}%              % Empty header styles
  \newpage%
  \if@twocolumn\hbox{}\newpage\fi\fi\fi}

\makeatother

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Prints your review date and 'Draft Version' (From Josullvn, CS, CMU)
\newcommand{\reviewtimetoday}[2]{\special{!userdict begin
    /bop-hook{gsave 20 710 translate 45 rotate 0.8 setgray
      /Times-Roman findfont 12 scalefont setfont 0 0   moveto (#1) show
      0 -12 moveto (#2) show grestore}def end}}
% You can turn on or off this option.
%\reviewtimetoday{\today}{Draft Version}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\usepackage{multirow}
\usepackage{slashbox}

\renewcommand{\epsilon}{\varepsilon}

% centered page environment

\newenvironment{vcentrepage}
{\newpage\vspace*{\fill}\thispagestyle{empty}\renewcommand{\headrulewidth}{0pt}}
{\vspace*{\fill}}


\renewcommand{\figurename}{Figure~}
%\usepackage[small,bf]{caption}

\addtokomafont{caption}{\small}
\setkomafont{captionlabel}{\small\bfseries}

\setcapindent{0em}
\usepackage{ifpdf}

\usepackage[b5paper,hyperindex=true,plainpages=false]{hyperref}


\renewcommand{\thefootnote}{\roman{footnote}}
\def\sectionautorefname{Section}
\def\subsectionautorefname{Section}
\def\subsubsectionautorefname{Section}
\usepackage{pdflscape}

\newenvironment{mysidewaystable}[1][htp]{\begin{sidewaystable}[#1]}{\end{sidewaystable}}

\renewcommand{\topfraction}{0.7}    % max fraction of floats at top
\renewcommand{\bottomfraction}{0.75}    % max fraction of floats at bottom
%   Parametres for TEXT pages (not float pages):
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{1}
\setcounter{totalnumber}{3}     % 2 may work better
 \setcounter{dbltopnumber}{2}    % for 2-column pages
\renewcommand{\textfraction}{0.05}  % allow minimal text w. figs
%   Parametres for FLOAT pages (not text pages):
\renewcommand{\floatpagefraction}{0.6}  % require fuller float pages
% N.B.: floatpagefraction MUST be less than topfraction !!
\usepackage[title,toc]{appendix}


% % % % % % % % %indice di capitolo
\def\ptctitle{indice di capitolo}                     % scrive quello che c'è tra {} al posto di Indice o Contents nei minitoc
\def\mtctitle{indice di capitolo}
\def\stctitle{indice di capitolo}
\setlength{\mtcindent}{3pt}               % indentazione del titolo del minitoc
\renewcommand{\mtifont}{
\small\scshape\lsstyle}  

 \usepackage{tocbibind}
\usepackage{mathtools}

\definecolor{NatGreen}{RGB}{50,93,61}
\newcolumntype{x}[1]{%
>{\raggedleft\hspace{0pt}}m{#1}}%


\hyphenation{mo-le-cu-lar ful-le-ro-pyr-ro-li-di-ne ful-le-ro-pyr-ro-li-di-nes his-to-grams his-to-gram pla-te-aus}

\hypersetup
{pdftitle={Spectroscopic Tools for Quantitative Studies of DNA Structure and Dynamics.},
pdfauthor={Søren Preus},
pdfsubject={PhD thesis. ``Spectroscopic Tools for Quantitative Studies of DNA Structure and Dynamics.'' }, %subject of the document
%pdftoolbar=false, % toolbar hidden
pdfmenubar=true, %menubar shown
pdfhighlight=/O, %effect of clicking on a link
colorlinks=true, %couleurs sur les liens hypertextes
pdfpagemode=UseOutlines,%UseNone, %aucun mode de page
pdfpagelayout=TwoPageRight,%SinglePage, %ouverture en simple page
pdffitwindow=true, %pages ouvertes entierement dans toute la fenetre
linkcolor=black, %couleur des liens hypertextes internes
citecolor=black, %couleur des liens pour les citations
urlcolor=black, %couleur des liens pour les url
bookmarksopenlevel=2
}


\usepackage[style=numeric,backend=bibtex,refsegment=chapter]{biblatex}



\begin{document} 
\titleformat{name=\section,numberless}[hang]{\usekomafont{section}}{}{.0em}{}

\pagenumbering{roman}
\dominitoc

\mainmatter
\chapter{try try try try try try try try try try try try try try try try try try try try try try try try try try try try try try}
\textit{try try try}
\vfill %da lo spazio
\minitoc %crea il mini indice
\newpage
%----------------------------------------------------------------------------------------
\section{try try try try try try try try  try try try try try try try try try try try try try try try try try try try try try try}
try try try try try try try try try try try try try try try try try try try try try try try try try try try try try try

\end{document}
share|improve this question
1  
Well, you could start by explaning what exactly you mean by wrapping? –  daleif Mar 12 at 14:17
    
Your code isn't exactly minimal, most of the preamble looks to be unrelated to the problem, would be nice if you could trim it down a bit. –  Torbjørn T. Mar 12 at 14:20
    
The problem is that when I have a long section the text comes off the edge. I put all that code because it is the preamble of my thesis. I do not know if there is qualcunna of those settings that can determine the problem. –  cesarino87 Mar 12 at 14:56
    
this is a preview [link] (dl.dropboxusercontent.com/u/15269862/cas.jpg) –  cesarino87 Mar 12 at 15:02
    
Part of the point of making an MWE is finding out where the problem lies. As you've redefined the section style, and section titles by default will break, you'll probably need that part, but this has nothing to do with for example floats, table, math, indexing, or graphics, so packages related to that can probably safely be removed. In the end though, it is a process of trial and error: Remove some stuff, and see if the example still compiles and the problem is visible. If no -> figure out what you shouldn't have removed and add it back in. If yes -> remove more stuff. Repeat. –  Torbjørn T. Mar 12 at 15:55

1 Answer 1

up vote 5 down vote accepted

The problem here is that you set the section title in a TikZ \node, and by default this is a box that doesn't allow line breaking, it will just become as wide as the contents of the node. To fix this, set a text width for the node, this will cause the node text to break when exceeding that width.

You probably also want to change the anchor of that node, or you may end up with part of the section title below the line you've drawn, if it needs several lines.

A minimal example:

enter image description here

\documentclass{scrartcl}

\usepackage{titlesec}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}
\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.south east, % bottom right corner of box with section number
               anchor=south west,            % bottom left corner of section title box
               text width=.7\linewidth]      % Change the width to whatever you want
               {#1};
     \end{tikzpicture}
 }}
\newcommand\boxedsection[1]{\boxedSectionB{#1}{\thesection}{2mm}}
 \titleformat{\section}[hang]%
     {\usekomafont{section}}%
     {}%
     {.0em}%
     {\filright\boxedsection}%


\begin{document} 

\section{try try try try try try try try  try try try try try try try try try try try try try try try try try try try try try try}
try try try try try try try try try try try try try try try try try try try try try try try try try try try try try try

\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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