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've got a custom style that is almost 100% working, but there's a few bugs I've noticed, and this one I can't seem to figure out.

\titleformat{\section}
  {\color{cyan}\itshape\LARGE}
  {\llap{\thesection\ }#1}
  {1em}
  {}
  [\titleline{\color{cyan}\titlerule[1pt]}]

In my cls file, I've got many bits of code, some of which may be conflicting here. When I make a new empty document based on the book class (and appending the above code into the preamble), everything works fine. But with my own class, the section text for an unnumbered section doesn't show.

Here's my cls file:

\LoadClass[10pt,letterpaper]{book}
\let\cleardoublepage\clearpage

\RequirePackage[
  left=2.25in,
  right=0.75in,
  top=1.25in,
  bottom=1.25in,
  marginparwidth=1.75in,
  marginparsep=.25in,
  asymmetric]{geometry}

\RequirePackage{graphicx}
\RequirePackage[hidelinks]{hyperref}
\RequirePackage{amsthm, amsfonts, amsmath}
\RequirePackage{thmtools}
\RequirePackage{paralist}
\RequirePackage{tikz}
\RequirePackage[explicit]{titlesec}
\RequirePackage{blindtext, xcolor}
\RequirePackage[T1]{fontenc}
\RequirePackage{mdframed}
\RequirePackage{DejaVuSansCondensed}
\RequirePackage[normalem]{ulem}
\RequirePackage{environ}
\RequirePackage[strict]{changepage}
\RequirePackage{fancyhdr}
\RequirePackage{calc}
\RequirePackage{titletoc}

\renewcommand*\familydefault{\sfdefault} % Set default font

\newcounter{definition}
\setcounter{definition}{0}

%%% Table of Contents ----------------------------------------------------------
\setcounter{tocdepth}{1} % Show only Chapters and Sections

% this stuff moved here for clarity
\makeatletter
\g@addto@macro{\appendix}{%
  \addtocontents{toc}{\protect\renewcommand*{\protect\@chapapp}{\protect\appendixname}}}

%%% Change font/color/layout of TOC

% START OF MODIFIED CODE

\contentsmargin{1.5cm} % global right margin, perhaps also global left

\titlecontents{chapter}[3cm] % <-- seems to set some specific left margin
{\color{cyan}\bfseries\LARGE\addvspace{3mm}}
{\makebox[0cm][r]{\@chapapp\hspace{.5em}\thecontentslabel\hspace{.75cm}}}
{} %     ^^^ pretendously zero width box puts its contents in the left margin
{\hfill\makebox[-3cm]{\thecontentspage}}  % 3cm = twice 1.5cm

\titlecontents{section}[3cm] % <-- again this left (additional?) margin
{\color{cyan}\large\itshape\addvspace{3mm}}
{\makebox[0cm][r]{\thecontentslabel\hspace{.75cm}}} % box pushed to the left
{}
{\hfill\makebox[-3cm]{\thecontentspage}}  % 3cm = twice 1.5cm
[\addvspace{0mm}]

% END OF MODIFICATIONS

\makeatother

\makeatletter
% Basically the same as for `\l@section` etc, just `\@nodottedtocline` instead of `\@dottedtcline`:
\newcommand*\l@chapterinfo{\@nodottedtocline{0}{7em}{2.1em}}
\newcommand*\l@sectioninfo{\@nodottedtocline{1}{7em}{2.1em}}

% Copied from the book class macro `\@dottedtocline`. Removed the dots and page number
\def\@nodottedtocline#1#2#3#4#5{%
  \ifnum #1>\c@tocdepth \else
    \vskip \z@ \@plus.2\p@
    {\leftskip #2\relax \rightskip \@tocrmarg \parfillskip -\rightskip
     \parindent #2\relax\@afterindenttrue
     \interlinepenalty\@M
     \leavevmode
     \@tempdima #3\relax
     \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip
     {#4}\nobreak
     \leaders\hbox{$\m@th
        \mkern \@dotsep mu\hbox{\,}\mkern \@dotsep
        mu$}\hfill
     \nobreak
     \hb@xt@\@pnumwidth{\hfil\normalfont \normalcolor }%
     \par}%
  \fi}
\makeatother

%%% New commands to add custom description to Chapter and Section.
\def\chapterinfo#1{%
    \addcontentsline{toc}{chapterinfo}{%
    \noexpand\numberline{}#1}}%

\def\sectioninfo#1{%
    \addcontentsline{toc}{sectioninfo}{%
    \noexpand\numberline{}#1}}%

%-------------------------------------------------------------------------------
%%% Header and Footer ----------------------------------------------------------

\pagestyle{fancy}
\fancyhf{} % sets both header and footer to nothing
\lhead[\textbf{\thepage}\hspace{7mm}\leftmark]{}
\rhead[]{\rightmark\hspace{7mm}\textbf{\thepage}}
\renewcommand{\headrulewidth}{0pt}
\fancyhfoffset[L]{1.5in}
\fancyhfoffset[R]{0in}

%-------------------------------------------------------------------------------
%%% Sction Styles --------------------------------------------------------------

\makeatletter
\titleformat{\chapter}
  {\normalfont\sffamily\Huge\scshape}
  {}
  {0pt}
  {
  \thispagestyle{empty}    % Remove page number on new chapters
  \setcounter{definition}{0}
  \begin{tikzpicture}[remember picture,overlay]
    \node[yshift=-3cm] at (current page.north west)
      {\begin{tikzpicture}[remember picture, overlay]
        \draw[fill=cyan] (0,-1) rectangle
          (25cm,3cm);
        \draw[fill=cyan] (0,-24) rectangle
          (25cm,-25cm);
        \ifttl@label% <---------------------- Added condition on \ifttl@label
          \node[anchor=west,xshift=.21\paperwidth,yshift=-.01\paperheight,rectangle]
              {\color{white}\LARGE \MakeUppercase{\@chapapp} \Huge\thechapter};
        \fi% <------------------------------- end condition on \ifttl@label
       \end{tikzpicture}
      };
    \end{tikzpicture}\endgraf
    \vskip-.7cm
    \color{cyan}\Huge\raggedright\leftskip-1cm
    \noindent\MakeUppercase{#1}\endgraf
  }
\makeatother
\titlespacing*{\chapter}{0pt}{10pt}{0pt}{}

\titleformat{\section}
  {\color{cyan}\itshape\LARGE}
  {\llap{\thesection\ }#1}
  {1em}
  {}
  [\titleline{\color{cyan}\titlerule[1pt]}]

\titleformat{\subsection}{\color{cyan}\normalfont\large}{\; #1}{1em}{}

%-------------------------------------------------------------------------------
%%% Custom Environments --------------------------------------------------------

\tikzstyle{cyanbox} = [draw=cyan!50, fill=cyan!10, very thick,
    rectangle, rounded corners, inner sep=10pt, inner ysep=20pt]
\tikzstyle{cyanbox2} = [draw=cyan!50, fill=cyan!10, very thick,
    rectangle, inner sep=10pt, inner ysep=20pt]

\tikzstyle{whitebox} = [draw=cyan!50, fill=white, very thick,
    rectangle, inner sep=10pt, inner ysep=20pt]
\tikzstyle{fancytitle} =[fill=cyan!50, text=white]

\def\thedefinition{\thechapter.\arabic{definition}}
\NewEnviron{definition}[1][Definition]{
  \stepcounter{definition}
  \begin{center}
    \begin{tikzpicture}
      \node [cyanbox] (box){%
          \begin{minipage}{.9\textwidth}
            \BODY
          \end{minipage}
      };
      \node[fancytitle, right=10pt] at (box.north west) {\bfseries$\bullet$ Definition \thedefinition};
      \end{tikzpicture}
    \end{center}}

\NewEnviron{emphasis}{
  \begin{center}
    \begin{tikzpicture}
      \node [whitebox] (box){%
          \begin{minipage}{.9\textwidth}
            \BODY
          \end{minipage}
      };
      \end{tikzpicture}
    \end{center}}

\NewEnviron{fullwidth}{
  \begin{adjustwidth}{-1.55in}{0in}
    \begin{center}
    \begin{tikzpicture}
      \node [cyanbox2] (box){%
          \begin{minipage}{\paperwidth - 1.8in}
            \BODY
          \end{minipage}
      };
      \end{tikzpicture}
    \end{center}
  \end{adjustwidth}}

\def\leftmarginshift{\marginparwidth + \marginparsep}
\def\rightmarginshift{\marginparsep}
\def\bodysize{\textwidth + \rightmarginshift}

\NewEnviron{myimage}[2]{
  \begin{adjustwidth}{-2.0in}{0.25in}
    asdf
    \begin{table}[h]
      \centering
%           \makebox[0pt][c]{\parbox{\textwidth}{%
      \begin{minipage}{2.0in}
        #1.#2
      \end{minipage}
      \begin{minipage}{\textwidth}
        \BODY
      \end{minipage}
%           }}
    \end{table}
  \end{adjustwidth}
  }

\NewEnviron{notation}{
  \begin{tikzpicture}
    \node [mybox] (box){%
        \begin{minipage}{.9\textwidth}
          \BODY
        \end{minipage}
    };
    \node[fancytitle, right=10pt] at (box.north west) {\bfseries Notation};
    \end{tikzpicture}}

%-------------------------------------------------------------------------------
%%% Custom Theorems ------------------------------------------------------------

\declaretheoremstyle[
    within=section,
    spaceabove=10mm,
    spacebelow=3mm,
    headfont=\color{cyan}\normalfont,
    notefont=\normalfont,
    bodyfont=\itshape,
    headpunct=\newline\newline,
    %postheadspace={10pt},
    notebraces={}{},
    headformat={%
        \makebox[-15pt][r]{\normalfont\large\NAME\ \NUMBER\;\;\;\;}\setbox0\hbox{\ }\hspace{-\the\wd0}\large\NOTE%
    },
]{theorem}
\declaretheorem[style=theorem]{theorem}
\declaretheorem[style=theorem]{example}

\declaretheoremstyle[
    within=section,
    spaceabove=10mm,
    spacebelow=3mm,
    headfont=\color{cyan}\normalfont,
    notefont=\normalfont,
    bodyfont=\itshape,
    headpunct=\newline\newline,
    %postheadspace={10pt},
    notebraces={}{},
    headformat={%
        \makebox[-10pt][r]{}\setbox0\hbox{\ }\hspace{-\the\wd0}\large\NAME%
    },
]{proof}
\let\proof\relax
\declaretheorem[style=proof,qed=\qedsymbol,name=Proof]{proof}
\declaretheorem[style=proof,qed=\qedsymbol,name=Solution]{solution}

Here's a MWE to go with it.

\documentclass{textbook}

\titleformat{\section}
  {\color{cyan}\itshape\LARGE}
  {\llap{\thesection}}
  {1em}
  {\sectiontitle}
  [\titleline{\color{cyan}\titlerule[1pt]}]

\begin{document}
\section*{Acknowledgement}% This section is not numbered
asdf
\chapter{test}
\end{document}

I can tell that the problem has to do with the #1 in my code. I've tried replacing with \sectiontitle, but that didn't work either.

share|improve this question
add comment

1 Answer 1

up vote 5 down vote accepted

The third mandatory argument to \titleformat is used for typesetting the number (when no * is used); the fourth is the separation between the number and the title, the fifth is used for typesetting the title. So what you want is

\titleformat{\section}
  {\color{cyan}\itshape\LARGE}
  {\llap{\thesection\ }}
  {0pt}
  {#1}
  [\titleline{\color{cyan}\titlerule[1pt]}]

This is the output of

\section*{Abc}
\section{Def}

enter image description here

Never use \makeatletter and \makeatother in a class file, where they are already implicit at the start and end respectively.

share|improve this answer
add comment

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.