1

I am making a template and trying to customize several things in it, and one of them is the section style. I created a command that makes a hexagon on the left side of the screen, as shown in the image below along with the code:

I am using more packages than this, but I think the essential ones for this problem are these.

\RequirePackage[%
    top =       2.5cm,    
    bottom =    3.8cm,    
    left =      2cm,    
    right =     2cm,
]{geometry}
\RequirePackage[most]{tcolorbox}
\RequirePackage{pgfplots}
\RequirePackage{graphicx}
\RequirePackage{xcolor}
\RequirePackage{tikz}
\RequirePackage{titletoc}
\RequirePackage{lmodern}
\usetikzlibrary{
    decorations.pathreplacing,
    decorations.pathmorphing,
    decorations.markings,
    shapes.multipart,
    shapes.geometric,
    arrows.meta,
    fadings,
    arrows,
    angles,
    quotes,
    calc,
    3d,
 }
\pgfplotsset{compat=1.18}
\definecolor{ChapterBackground}{HTML}{101010} % PERSONAL BLACK
\definecolor{ChapterForeground}{HTML}{e93820} % PERSONAL ORANGE I

\newcommand{\polygonSection}{%
\begin{tikzpicture}[remember picture, overlay]
\foreach \i in {0.5,...,5}{%
    \node[%
        ChapterBackground,
        regular polygon sides   = 6, 
        regular polygon,
        rounded corners,
        minimum size            = \i cm,
        ultra thick,
        draw,
    ] at ($(current page.north west |- current page text area.west)+(0,0)$) {};
}

\node[%
    regular polygon sides   = 6, 
    rounded corners,
    regular polygon,
    minimum size            = 1.58 cm,
    ultra thick,
    inner sep               = 0,
    fill                    = ChapterForeground!85,
    text                    = ChapterForeground!5,
] at ($(current page.north west |- current page text area.west)+(0,0)$) {};

\end{tikzpicture}}

enter image description here

Well, with this command I tried to use \titleformat{} from the titlesec package to style my section as follows:

\titleformat{\section}[display]
{\normalfont\bfseries\color{ChapterBackground}}{}{1em}
{\llap{
\polygonSection\hspace{-6pt}}\huge\textsc}[]

enter image description here

However, I would like to align the title with the hexagon and add a small space between the two, but I have not found any way to do this, and I am getting the following error message:

Package pgf Error: No shape named `current page text area' is known.

However, if I take this part out of the code, it doesn't look the way I want. Also, using the tikzpagenodes package, the polygons are no longer separated by sections, but by pages, which is not what I want.

That's it, if anyone can help me, that would be great.

1
  • Since it is unclear how large the margins are, could you please add the settings for geometry? Mar 3, 2023 at 13:01

1 Answer 1

2

I am not sure whether it is a good idea to indent the section title so that it starts further to the right than the body text. Maybe you should rather increase the left margin. Anyways, the following should do about what you want:

\documentclass{article}

\RequirePackage[%
    top    = 2.5cm,    
    bottom = 3.8cm,    
    left   =   2cm,    
    right  =   2cm,
]{geometry}

\RequirePackage{tikz}
\usetikzlibrary{shapes.geometric}

\definecolor{ChapterBackground}{HTML}{101010} % PERSONAL BLACK
\definecolor{ChapterForeground}{HTML}{e93820} % PERSONAL ORANGE I

\newcommand{\polygonSection}{%
\begin{tikzpicture}[remember picture, overlay] 
\node[%
    regular polygon sides   = 6, 
    rounded corners,
    regular polygon,
    minimum size            = 1.58cm,
    ultra thick,
    inner sep               = 0pt,
    fill                    = ChapterForeground!85,
    anchor                  = south
] at (current page.north west |- 0,0) (red polygon) {};
\foreach \i in {2.5,...,4.5}{%
    \node[%
        ChapterBackground,
        regular polygon sides   = 6, 
        regular polygon,
        rounded corners,
        minimum size            = \i cm,
        ultra thick,
        draw,
    ] at (red polygon) {};
}
\end{tikzpicture}}

\RequirePackage{titlesec}
\titleformat{\section}[display]
    {\normalfont\bfseries\color{ChapterBackground}\huge}{}{0pt}
    {\polygonSection\hspace{1em}}

\usepackage{lipsum}

\begin{document}

\section{Section}

\lipsum[1]

\end{document}

enter image description here

How does this work? The tikzpicture that we add to the section title first places the red hexagon which is anchored shouth, so that it horizontally sits on the baseline of the tikzpicture and vertically at the left edge of the paper. The other hexagons (of which you only really need three, so I adjusted the \foreach list) are then centered around this red hexagon.

You can adjust the spacing by inserting some space using \titleformat{\section}, but as I said in the beginning, it might be better to increase the left margin of your document alltogether.

If you want to center the hexagons vertically, remove anchor = south from the options for the red hexagon and add baseline = -0.5ex to the options for the tikzpicture environment.


Some remarks: tcolorbox loads tikz, pgfplots also loads tikz and tikz loads xcolor. It is therefore not necessary to load all these packages together. You should also really think about which TikZ libraries you really need. For the above, only shapes.geometric is needed.

2
  • How I can align the title with the hexagon center? Something always goes wrong when I try.
    – Jimeens
    Mar 3, 2023 at 13:16
  • @Jimeens You can add baseline=1.5ex to the options of the tikzpicture. I thought you wanted to align the hexagon with the baseline. Mar 3, 2023 at 13:19

You must log in to answer this question.

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