0

I want to insert an icon into the margin adjacent to a section header. I have defined a set of diverse section headers, as shown in MWE.

Therein, I insert the graphic using marginpar and reversemarginpar. If additional text is inserted, so that the graphics flow to the next page, they no longer place the graphics as desired (e.g. toggle lipsum [3]).

I wish to incorporate these two longhand expressions into a single command, such as /talk, which will then automatically insert the icon into the appropriate margin, regardless of whether it is a left or right facing page. (My failed attempt at this is included as a comment below the MWE)

I want to incorporate the command within the /reflect command, so the graphic appears whenever that command is issued.

Thank you.

enter image description here enter image description here

%   MWE 

    \documentclass[a5paper, openany]{memoir}     
    \usepackage{fontspec} 
    \setmainfont[Ligatures=TeX]{Gill Sans}
    \setromanfont[Ligatures=TeX]{Gill Sans Light}
    \setlrmarginsandblock{0.85in}{0.85in}{*}    
    \usepackage{lipsum}
    \usepackage[usenames,dvipsnames]{xcolor}        
            \definecolor{bar}{gray}{0.7}

%   section bar headings defined, using tikz
    \usepackage[explicit]{titlesec}         
    \usepackage{tikz}
    \usetikzlibrary{shapes.misc}
    \makeatletter
    \let\currentsectiontitle\relax
%   section bar specs           
    \newcommand\sectionbar{
    \tikz[baseline,trim left=\trim,trim right=\trimright]{
                \fill [\barfill] (2.25cm,-1ex) rectangle (\textwidth+2.25cm,2.5ex); 
                \node [fill=\markerfill, 
                anchor= base east, rounded rectangle, minimum height=3.5ex] at 
                (13.8cm,{\vertical+\vadjust}) 
            {\sectionmarker};   % label sectionmarker
        \node [fill=\barfill, 
            anchor= base east, rounded rectangle, minimum height=3.5ex] at 
                (\markerinset,\vertical) {};            %   circle-left-end
        }}              
%   margins, adjustments        
    \def\trim{2.75cm}           %   section bar 
    \def\trimright{2.6cm}       %   header text 
    \def\markerinset{2.6cm}     %   section tag 
    \def\vertical{0.13}         
    \def\vadjust{-0.0875}       
    \def\markerfill{black}      %   shade (colours.tex)
    \def\barfill{bar}                   
%   section bar format
    \renewcommand*{\thesection}{\arabic{section}}
    \def\markerfont{\usefont{main}{m}}
    \titleformat    {\section}{\large\bfseries}{\textnormal\@topic}{-0.1cm}
                {\gdef\currentsectiontitle{#1}#1}   
%   section marker labels
    \def\@@topic{Topic \space \thesection}      
    \def\@@summary{Summary}
%   section marker variations  
    \newcommand\@topic      
        {\def\sectionmarker{\color{white}{\@@topic}}\sectionbar}
    \newcommand\@summary
        {\def\sectionmarker{\color{white}{\@@summary}}\sectionbar}
    \newcommand\@reflection
        {\def\sectionmarker{\color{white}{\@@reflection}}\sectionbar}       
    \newcommand{\summarise}[1]  
        {\section*{\textnormal\@summary#1}}
    \newcommand{\reflect}[1]        
        {\section*{\textnormal\@topic#1}}
    \makeatother

    \begin{document}
    \chapter{Title}
    \label{title}
    \section{First section}
    \label{firstsection}
    \section{Terms used in this study}
    \label{termsusedinthisstudy}
    \reflect{Reflection}
         \reversemarginpar{
            \vskip-1.25cm
            \hspace{-1.5cm}
            \includegraphics[width=30pt]{icons/talk.png}}
    \summarise{Study 1 Summarised}
    \label{study1summarised}
    \lipsum[1]
%   \lipsum[3]
%   \lipsum[3]
    \reflect{Reflection}
         \marginpar{
            \vskip-1.25cm
            \hspace{-12.25cm}
            \includegraphics[width=30pt]{icons/talk.png}}
    \end{document}


%       rudimentary attempt to create command - FAIL
%       \newcommand{\talk}[1]{
%        \marginpar{
%           \vskip-1.25cm
%           \hspace{-12.25cm}
%           \includegraphics[width=30pt]{icons/talk.png}}
%       \reversemarginpar{
%           \vskip-1.2cm
%           \hspace{-12.0cm}
%           \includegraphics[width=30pt]{icons/talk.png}}
%       }
  • Your MWE didn't work for me using pdflatex. Eventually processed it by Lualatex but then it didn't finf the font GillSans nor the graphic icons/talk.png. Please provide a MWE that does not require special fonts or graphics that only you might have. – Peter Wilson Mar 24 at 19:25
  • The fonts can be remarked out. I'm uncertain how to cross reference an image / icon such as the one that is required in this instance. Obviously, a similar image could be substituted locally. But can one be uploaded alongside the MWE? – johnbrc Mar 24 at 20:58
0

I found a way that was sufficiently close to what I required.

enter image description here

%   -------------------------------
%   Section heading styling
%   -------------------------------
%   creates grey bars beneath section headings 
    \usepackage[explicit]{titlesec}         
    \usepackage{tikz}
    \usetikzlibrary{shapes.misc}
    \makeatletter
    \let\currentsectiontitle\relax
%   section bar specs           
    \newcommand\sectionbar{
    \tikz[baseline,trim left=\trim,trim right=\trimright]{
                \fill [\barfill] (2.25cm,-1ex) rectangle (\textwidth+2.25cm,2.5ex); 
                \node [fill=\markerfill, 
                anchor= base east, rounded rectangle, minimum height=3.5ex] at 
                (13.8cm,{\vertical+\vadjust}) 
            {\sectionmarker};   % label sectionmarker
        \node [fill=\barfill, 
            anchor= base east, rounded rectangle, minimum height=3.5ex] at 
                (\markerinset,\vertical) {};            %   circle-left-end
        }}  
    \newcommand\reflectionbar{
    \tikz[baseline,trim left=\trim,trim right=\trimright+5pt]{
                \fill [\barfill] (2.25cm,-1ex) rectangle (\textwidth+2.25cm,2.5ex); 
                \node [fill=\markerfill, 
                anchor= base east, rounded rectangle, minimum height=3.5ex] at 
                (13.8cm,{\vertical+\vadjust}) 
            {\sectionmarker};   % label sectionmarker
        \node [fill={white},draw={black}, 
            anchor=east, circle, minimum height=2.0ex](image) at 
                (\markerinset-1pt,\vertical) {\includegraphics[width=15pt]{talk.png}};          %   circle-left-end
        }}              

%   margins, adjustments        
    \def\trim{2.75cm}           %   section bar 
    \def\trimright{2.6cm}       %   header text 
    \def\markerinset{2.6cm}     %   section tag 
    \def\vertical{0.13}         
    \def\vadjust{-0.0875}       
    \def\markerfill{marker}     %   shade (colours.tex)
    \def\barfill{bar}                   
%   section bar format
    \renewcommand*{\thesection}{\arabic{section}}
    \def\markerfont{\usefont{main}{m}}
%   toggle
%   \iftoggle{rh}{  
%       \titleformat    {name=\section,numberless}
%                       {\large\bfseries}{\sectionbar}{0.1cm}
%                   {\gdef\currentsectiontitle{#1}#1}   }{
        \titleformat    {name=\section}
                    {\large\bfseries}{\textnormal\@topic}{-0.1cm}
                    {\gdef\currentsectiontitle{#1}#1}   
%                   }
%   section marker labels
    \def\@@topic{Topic \space \thesection}      
    \def\@@summary{Summary}
%   \def\@@reflection{Reflect}
%   section marker variations  
    \newcommand\@topic      
        {\def\sectionmarker{\color{white}{\@@topic}}\sectionbar}
    \newcommand\@summary
        {\def\sectionmarker{\color{white}{\@@summary}}\sectionbar}
    \newcommand\@reflection
        {\def\sectionmarker{\color{white}{\@@topic}}\reflectionbar}

%   commands -- insert into Scrivener sections
    \newcommand{\summarise}[1]  {\section*{\textnormal\@summary#1}}
    \newcommand{\reflect}[1]        {\section*{\textnormal\@reflection#1}}
%   end
    \makeatother

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.