2

Based upon this original post include section name, as well as number in mdframed (theorem) header, I am using tikz to create a series of bars and markers (e.g. Topic No, Summary, topic summary), thus:

Section header bars, including numbered option

After innumerable hours of development and experimentation, I seemed to have reached a limit and am requesting help to complete the development of this macro. In particular, I need to better understand how to produce the lower two or three section bars to a particular specification.

  1. I would like each of the three 'markers' to be in a REGULAR typeface, whilst the section header text itself remains emphasised strongly (i.e bold). I have partially achieved this effect for the second section bar. N.b. Document's default roman typeface is Gill Sans Light (see lipsum par.), whilst Gill Sans (Regular) is set as mainfont.

  2. I would like the section header text to properly align left, i.e. as normal text and first two section headers.

  3. I am aware that my definition of the new commands \ssection and \tsection is poor. Although they work, I suspect that I have not achieved this "appropriately"—though I'm not sure why.


If anyone can go further, I would ideally like to reverse the section bars with markers, by placing the markers on the left of the page, with section header text flushright. When I experimented with doing this directly, by inserting this command into the \titleformat command, it moved everything in a manner that was beyond me to develop usefully. Perhaps there are other ways of using tikz (styles?) that would be more efficient. But perhaps this should be the topic of a separate question…?


A MWE follows.

Note: it incorporates a couple of options (using toggle), which allow for an handbook option (fh), in which ALL section headers are unnumbered and a French translation option (fr), both of which are set to false in this example. I recognise that this is therefore not technically a minimum working example, but hope you are able to indulge me, since removing the toggles would require redefining integral elements of the macro.

With appreciation for assistance and advice given.

    \documentclass[a5paper, openany]{memoir}     

    \usepackage{fontspec}                           %   glurl.co/fs0
    \setmainfont[Ligatures=TeX]{Gill Sans}
    \setromanfont[Ligatures=TeX]{Gill Sans Light}

\setlrmarginsandblock{0.85in}{0.85in}{*}    

    \usepackage{lipsum}
    \usepackage{etoolbox}
            \newtoggle{fr}
            \newtoggle{fh}  
            \togglefalse{fr}            %   english     
            \togglefalse{fh}        %   module handbook

\usepackage[usenames,dvipsnames]{xcolor}        
            \definecolor    {bar}           {gray}{0.7}
            \definecolor    {marker}        {named}{black}

%   section bar headings defined, using tikz

\usepackage[explicit]{titlesec}         %   glurl.co/dFH
\usepackage{tikz}
\usetikzlibrary{shapes.misc}

\makeatletter
\let\currentsectiontitle\relax

\newcommand\sectionbar{
            \tikz[baseline,trim left=\trim,trim right=\trim] {
                \fill [\barfill] (2.25cm,-1ex) rectangle (\textwidth+3cm,2.5ex);
                \node [ fill=\markerfill, anchor= base east, rounded rectangle,
                        minimum height=3.5ex] at 
                (13.8cm,{\vertical+\vadjust}) {\sectionmarker};
                \node [ fill=\barfill, anchor= base east, rounded rectangle,
                        minimum height=3.5ex] at 
                (\markerinset,\vertical) {};
                    }}          

        \def\sectionmarker{}
        \def\barfill{bar}
        \def\markerfill{bar}

        \def\trim{2.8cm}
        \def\vertical{0.1435}
        \def\vadjust{0}
        \def\markerinset{2.6cm}

\iftoggle{fh}{
            \titleformat{name=\section,numberless}      %   http://glurl.co/e7H
                {\large\bfseries}{\sectionbar}
                {0.1cm}{\gdef\currentsectiontitle{#1}#1}    
                }{
            \iftoggle{fr}{      
        \def\@@topic{Th\`eme}       
                \def\@@summary{R\'esum\'e}
                \def\@@topicsummary{R\'esum\'e du Th\`eme}
                }{
                \def\@@topic{Topic}         
                \def\@@summary{Summary}
                \def\@@topicsummary{topic summary}
                 }

\newcommand\@sectionbar{
    \def\trim{3.5cm}
    \def\vadjust{-0.0875}
    \def\markerfill{marker}
    \sectionbar}

\newcommand\@topic{
    \def\sectionmarker{\color{white}{\space \@@topic \space \thesection}}
            \@sectionbar}

\newcommand\@summary{
        \def\sectionmarker{\color{white}{\@@summary}}
            \@sectionbar}

\newcommand\@topicsummary{
        \def\sectionmarker{\color{white}{\@@topicsummary}}
            \@sectionbar}

\newcommand\titlebar{\@ifstar\sectionbar\@topic}

\titleformat
    {\section}
    {\large}        %   \flushright, \raggedleft
    {\titlebar}
    {-0.68cm}
    {\bfseries\gdef\currentsectiontitle{#1}#1}

\renewcommand*  {\thesection}   {\arabic{section}}

\newcommand {\osection}[1]  {\section*{\sectionbar#1}}
\newcommand {\ssection}[1]  {\section*{\@summary#1}}    
\newcommand {\tsection}[1]  {\section*{\@topicsummary#1}}
    }%end-toggle
\makeatother


    \begin{document}

    \chapter{Title}
    \label{title}

    \osection{Terms used in this study}
    \label{termsusedinthisstudy}

    \section{First section}
    \label{firstsection}

    \tsection{Topic summarised}
    \label{topicsummarised}

    \ssection{Study 1 Summarised}
    \label{study1summarised}

\lipsum[1]

    \end{document}
5
  • Do you know where can I get (a free version of) Gill Sans and Gill Sans Light in ttf format? Commented Mar 9, 2015 at 23:22
  • And also, what should happen with long titles spanning more than one line? Commented Mar 9, 2015 at 23:35
  • Apparently, from here: ufonts.com/fonts/gillsans.html
    – johnbrc
    Commented Mar 10, 2015 at 9:54
  • As for long titles, spanning more than a single line, I have eradicated them from my text, so I have no stipulation.
    – johnbrc
    Commented Mar 10, 2015 at 9:55
  • the light variant: ufonts.com/fonts/gillsans-light.html
    – johnbrc
    Commented Mar 10, 2015 at 10:03

1 Answer 1

1

I found a way to achieve the desired result. Defining trim right with a separate token trimright was critical, even when the value was the same as trim left (i.e. trim). This caused the section header text in ssection and tsection to line up with that in osection. Then it was mainly a matter of defining the alternate values between sectionbar and @sectionbar respectively.

I incorporated \textnormal to lift the incumbent emphasis off the marker text. I would still like to change marker typeface to the medium weight font, but I trust this is simply a matter of further research, particularly since the font I want to use is already defined as the setmainfont (at present, setromanfont, the 'light' version of the typeface is used throughout).

Resulting macro:

    \documentclass[a5paper, openany]{memoir}     

    \usepackage{fontspec}                           %   glurl.co/fs0
    \setmainfont[Ligatures=TeX]{Gill Sans}
    \setromanfont[Ligatures=TeX]{Gill Sans Light}

\setlrmarginsandblock{0.85in}{0.85in}{*}    

    \usepackage{lipsum}
    \usepackage{etoolbox}
            \newtoggle{fr}
            \newtoggle{fh}  
            \togglefalse{fr}        %   english     
            \togglefalse{fh}        %   module handbook

\usepackage[usenames,dvipsnames]{xcolor}        
            \definecolor    {bar}           {gray}{0.7}
            \definecolor    {marker}        {named}{black}

%   section bar headings defined, using tikz

\usepackage[explicit]{titlesec}         %   glurl.co/dFH
\usepackage{tikz}
\usetikzlibrary{shapes.misc}

\makeatletter
\let\currentsectiontitle\relax

\newcommand\sectionbar{
            \tikz[baseline,trim left=\trim,trim right=\trimright] {
                \fill [\barfill] (2.25cm,-1ex) rectangle (\textwidth+3cm,2.5ex);
                \node [fill=\markerfill, anchor= base east, rounded rectangle,
                        minimum height=3.5ex] at 
                (13.8cm,{\vertical+\vadjust}) {\sectionmarker};
                \node [fill=\barfill, anchor= base east, rounded rectangle,
                        minimum height=3.5ex] at 
                (\markerinset,\vertical) {};
                    }}          

        \def\sectionmarker{\null}
        \def\barfill{bar}
        \def\markerfill{bar}

        \def\trim{2.815cm}% inset unmarked bar
        \def\trimright{2.7cm}% inset header to match text
        \def\markerinset{2.6cm}
        \def\vertical{0.145}
        \def\vadjust{0}

\iftoggle{fh}{
            \titleformat{name=\section,numberless}  %   http://glurl.co/e7H
                {\large\bfseries}{\sectionbar}
                {0.1cm}{\gdef\currentsectiontitle{#1}#1}    
                }{
            \iftoggle{fr}{      
        \def\@@topic{Th\`eme}       
                \def\@@summary{R\'esum\'e}
                \def\@@topicsummary{R\'esum\'e du Th\`eme}
                }{
                \def\@@topic{Topic}         
                \def\@@summary{Summary}
                \def\@@topicsummary{topic summary}
                 }

\newcommand\@sectionbar{
    \def\trim{3.6cm}% inset marked bars
        \def\trimright{2.75cm}% inset marked headers to match text
        \def\markerinset{2.58cm}
        \def\vertical{0.13}
    \def\vadjust{-0.0875}
    \def\markerfill{marker}
    \sectionbar}

\newcommand\@topic{
    \def\sectionmarker{\color{white}{\space \@@topic \space \thesection}}
            \@sectionbar}

\newcommand\@summary{
        \def\sectionmarker{\color{white}{\@@summary}}
            \@sectionbar}

\newcommand\@topicsummary{
        \def\sectionmarker{\color{white}{\@@topicsummary}}
            \@sectionbar}

\titleformat
    {\section}
    {\large\bfseries}       %   \flushright, \raggedleft
    {\textnormal\@topic}
    {-0.01cm}
    {\gdef\currentsectiontitle{#1}#1}

\renewcommand*{\thesection}{\arabic{section}}

\def\markerfont{\usefont{main}{m}}   % use 'main' font?

\newcommand{
        \osection}[1]{
                \section*{\sectionbar#1}}
\newcommand{
        \ssection}[1]{
                \section*{\textnormal\@summary#1}}  
\newcommand{
        \tsection}[1]{
                \section*{\textnormal\@topicsummary#1}}
    }%end-toggle
\makeatother


    \begin{document}

    \chapter{Title}
    \label{title}

    \section{First section}
    \label{firstsection}

    \osection{Terms used in this study}
    \label{termsusedinthisstudy}

    \tsection{Topic summarised}
    \label{topicsummarised}

    \ssection{Study 1 Summarised}
    \label{study1summarised}

\lipsum[1]

    \end{document}

Resulting pdf:

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .