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

选自:https://tex.stackexchange.com/questions/232190/using-tikz-to-create-section-bars-and-markers

点赞(1)

评论列表 共有 0 条评论

暂无评论
立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部