1

I'm wanting to adapt the following macro(s) to provide three different options of style heading. At the moment, if offers two, one if the section is normal (numbered) and another for section* (un-numbered). I want a second un-numbered option (which will have an margin image (with a second, different icon to people.pdf) instead).

I've remarked-out (%) the two lines with ssection in them (i.e. the inadequate definition and the corresponding line in the sample document), because that produces an error. I understand that it can't be done simply by adding a third definition, because there's an ifstar statement with only two options, not three. Thus I'm unsure how to proceed.

Existing macro outputs thus: http://cl.ly/082k1i2w0e2t/sidebar-images.pdf

(I'd also be interested to know if there is a way of adapting a subsequent titlebar@@@ definitions by building on one of the other ones…but perhaps that warrants a separate question?)

\documentclass{report}
\usepackage{graphicx}
\usepackage[nopar]{lipsum}
\usepackage[noadjust]{marginnote}

\usepackage{titlesec}
\usepackage{tikz}\usetikzlibrary{shapes.misc}
\makeatletter

%   number section bar      
\newcommand\titlebar@{%sections
\tikz[baseline,trim left=3.1cm,trim right=3.0cm] {
    \fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
    \node [
        fill=black!100!white,
        anchor= base east,
        rounded rectangle,
        minimum height=3.75ex] at (3cm,0.01) {
        \color{white}\textbf{T\thesection}
            };
}}

%   section bar, icon 1 
\newcommand\titlebar@@{%osections
\tikz[baseline,trim left=3.1cm,trim right=3.15cm] {
    \fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
    }
\marginpar{\vskip-1.9cm\hspace{-14cm}
\includegraphics[width=\marginparwidth]
{people.pdf}    }
    }

%   section bar, icon 2 
\newcommand\titlebar@@@{%ssections
\tikz[baseline,trim left=3.1cm,trim right=3.15cm] {
    \fill [black!15] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
    }
\marginpar{\vskip-1.9cm\hspace{-14cm}
\includegraphics[width=\marginparwidth]{people.pdf}}}

%   make title commands
\newcommand\titlebar{\@ifstar\titlebar@@\titlebar@}
\titleformat{\section}{\large\bfseries}{\titlebar}{0.1cm}{}
\renewcommand*{\thesection}{\arabic{section}}
\newcommand{\osection}[1]{\section*{\titlebar*#1}}
%   \newcommand{\ssection}[1]{\section*{\titlebar*#1}}
\makeatother





\begin{document}
  \chapter{test}
\osection{person}
    \lipsum[1]
\section{another}
\lipsum[1]  
%\ssection{another}
\lipsum[1]  
\end{document}
1

You make this in a wrong way Define 3 command

\renewcommand{\sectionOne}[1]{\global\def\titlebar{\titlebar@}\section{#1}}
\renewcommand{\sectionTwo}[1]{\global\def\titlebar{\titlebar@@}\section{#2}}
\renewcommand{\sectionTree}[1]{\global\def\titlebar{\titlebar@@@}\section{#3}}

moreother if you are using consécutively the same title bar style you can call the custom command only once and call \section for the other times.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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