将图形插入到节标题的边缘

将图形插入到节标题的边缘

我想在节标题旁边的空白处插入一个图标。我定义了一组不同的节标题,如 MWE 中所示。

marginpar其中,我使用和插入图形reversemarginpar。如果插入了其他文本,以便图形流到下一页,它们不再按需要放置图形(例如切换 lipsum [3])。

我希望将这两个手写表达合并为一个命令,例如 /talk,这样它就会自动将图标插入到适当的页边距中,无论它是左页还是右页。(我失败的尝试包含在 MWE 下方的评论中)

我想将该命令合并到 /reflect 命令中,这样只要发出该命令就会出现图形。

谢谢。

在此处输入图片描述 在此处输入图片描述

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

答案1

我找到了一种足够接近我需要的方法。

在此处输入图片描述

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

相关内容