저는 템플릿을 만들고 그 안의 여러 가지를 사용자 정의하려고 하는데 그 중 하나가 섹션 스타일입니다. 코드와 함께 아래 이미지와 같이 화면 왼쪽에 육각형을 만드는 명령을 만들었습니다.
이보다 더 많은 패키지를 사용하고 있는데, 이 문제를 해결하는데 꼭 필요한 패키지는 바로 이것들이라고 생각합니다.
\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}}
음, 이 명령을 사용하여 titlesec 패키지의 \titleformat{}을 사용하여 다음과 같이 섹션 스타일을 지정하려고 했습니다.
\titleformat{\section}[display]
{\normalfont\bfseries\color{ChapterBackground}}{}{1em}
{\llap{
\polygonSection\hspace{-6pt}}\huge\textsc}[]
그러나 제목을 육각형에 맞춰 정렬하고 둘 사이에 작은 공간을 추가하고 싶지만 이를 수행할 방법을 찾지 못하여 다음과 같은 오류 메시지가 나타납니다.
패키지 pgf 오류: '현재 페이지 텍스트 영역'이라는 모양이 알려져 있지 않습니다.
그런데 이 부분을 코드에서 빼면 제가 원하는 모양이 나오지 않네요. 또한 tikzpagenodes 패키지를 사용하면 다각형이 더 이상 섹션으로 분리되지 않고 페이지로 분리되는데 이는 내가 원하는 것이 아닙니다.
누구든지 나를 도울 수 있다면 좋을 것입니다.
답변1
섹션 제목을 본문 텍스트보다 오른쪽에서 시작하도록 들여쓰는 것이 좋은 생각인지 잘 모르겠습니다. 어쩌면 왼쪽 여백을 늘려야 할 수도 있습니다. 어쨌든 다음은 원하는 작업을 수행해야 합니다.
\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}
어떻게 작동하나요? 섹션 제목에 추가한 는 tikzpicture
먼저 고정된 빨간색 육각형을 배치하여 수평으로 기준선에, tikzpicture
수직으로 용지 왼쪽 가장자리에 놓이도록 합니다. 다른 육각형(실제로는 3개만 필요하므로 목록을 조정함 \foreach
)은 이 빨간색 육각형을 중심으로 배치됩니다.
를 이용하여 공백을 넣어서 간격을 조절할 수도 있지만 \titleformat{\section}
, 처음에 말씀드린 것처럼 문서의 왼쪽 여백을 한꺼번에 늘리는 것이 더 나을 수도 있습니다.
육각형을 세로로 가운데에 배치하려면 anchor = south
빨간색 육각형 옵션에서 제거하고 baseline = -0.5ex
환경 옵션에 추가하세요 tikzpicture
.
몇 가지 참고 사항: tcolorbox
로드 tikz
, pgfplots
로드 tikz
및 tikz
로드 도 가능합니다.xcolor
도 있습니다 . 따라서 이러한 패키지를 모두 함께 로드할 필요는 없습니다. 당신은 또한 어떤 Ti에 대해 정말로 생각해야 합니다케이Z 라이브러리가 정말 필요합니다. 위의 경우에만 shapes.geometric
필요합니다.