2

I managed to create a custom sectioning command because of Werner's help here and–in relation to the optional arguments–this solution here.

Is it possible to enhance the macro for a sectioning command with tikz features? I'd like to reference the corners of the heading itself and thought to wrap it in a node command. Well it was worth a try, but maybe tikz is not the right tool for this or I just lack the deeper knowledge of LaTeX?

In relation to the mockup-picture, I would like to

  1. get rid of space above the horizontal part of the tikz lines (which are located above the section-command, i.e. the space is marked with blue) and

  2. have the vertical tikz lines reach the lower corner of the heading (the red part of the tikz lines, i.e. directly next to the heading itself).

Are these 2 points possible?

With help/a hint by Martin, I managed to create a version of what I intend, but it clearly is not fully functional yet (it produces errors) and does not look like it should.

Mock-up of goal

enter image description here

Screenshot of MWE (not working)

enter image description here

MWE

\documentclass[
11pt,
a4paper,
parskip=false-
]
{scrartcl}

\usepackage{
lmodern,
blindtext,
multicol,
tikz,
etoolbox
}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\RedeclareSectionCommands[
    beforeskip=0pt,
    afterskip=3pt,
    tocentryformat=\small,
    toclinefill=\small\TOCLineLeaderFill,
    tocpagenumberformat=\small,
%   addtokomafont=\Large
]{subsection}
\addtokomafont{subsection}{\Large}

%=================================
% hide section headings - circumvent with fake heading
%src: https://tex.stackexchange.com/a/129985/25683
%=================================
\newcommand{\myownsec}[1]{%
  \par\refstepcounter{section}% Increase section counter
  \sectionmark{#1}% Add section mark (header)
%  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}% Add section to ToC
  \addcontentsline{toc}{section}{#1}% Add section to ToC
  % Add more content here, if needed.
}

%***********************************************************
%***********************************************************
%       OLD version - works, but does not look the part
% (src: https://tex.stackexchange.com/a/586911/25683)
%***********************************************************
%***********************************************************
%\NewDocumentCommand{\specialthing}{ o m }{%
%%\par\vspace{0ex}
%\begin{tikzpicture}
%[
%overlay,
%]
%\draw[
%semithick,
%color={black!30!blue},
%] (0,0) -- (0.95\columnwidth,0) -- (0.95\columnwidth,-0.5);
%\draw[
%semithick,
%color={black!50!green}
%] (0.1,-0.1) -- (0.94\columnwidth,-0.1) -- (0.94\columnwidth,-0.4);
%\end{tikzpicture}\par\vspace{0ex}
%\subsection[\IfValueTF{#1}{#1}{#2}]{#2}
%}

%***********************************************************
%***********************************************************
%  NEW version - does not work, would probably look like it should
%***********************************************************
%***********************************************************
\newrobustcmd{\specialthing}[1]{%
    \texorpdfstring{%
        \begin{tikzpicture}
            \node (sectionnode) {#1};
            \draw[orange] (sectionnode.north west) -- (sectionnode.north east) -- (sectionnode.south east);
        \end{tikzpicture}}{8iohsdfg}}

%\DeclareRobustCommand{\specialthing}{\texorpdfstring{\tikz\node{pgf};}{replacement text}}

%\chapter{hello \TikzStuff}

%\usepackage[showframe]{geometry}

\listfiles
\begin{document}
\begin{multicols*}{2}

\myownsec{Word}
%\tikz\node{pgf};\\

\subsection{bla \specialthing{asdf}}
\blindtext[1]

\blindtext[1]

\blindtext[1]

\blindtext[1]

%\specialthing{AAAAAA aaaa bbbb cccc dd eeeee}
\blindtext[1]

\end{multicols*}
\end{document}
3
  • I dont really know how to do what you ask here, but I can tell you that the asdf is raised because you have not set the inner and outer separation of the node to 0. If you write in your specialthing the following: \node[inner sep = 0, outer sep = 0pt] , then you will see that asdf is in line with the rest. How to keep going afterwards, I cannot help you :(
    – Jes
    Mar 14 at 12:46
  • Also the {8iohsdfg} is on purpose, right? You are introducing it by using your command
    – Jes
    Mar 14 at 12:47
  • @Jes Hi Jes, thank you for the remarks. I accounted for the inner sep-values. Also, yes, the "8io.." was a stupid oversight.
    – henry
    Mar 14 at 19:58
2

To the best of my knowledge and with help from:

  1. https://tex.stackexchange.com/a/249111/25683

  2. https://tex.stackexchange.com/a/11570/25683 - I used this reply to guesstimate the horizontal length (i.e. width) of \thesection plus the horizontal space behind it, the one which ends before the heading text itself). It seems to land at roughly 1.1em. => CAREFUL The code part which uses this length produces "ugly", for the lack of a better term, results if the sectioning numbers get higher than 9, i.e. at least in the 2 digits-range. Also, I am unable to influence any vertical offset because of the bottom-aligned sectioning number.

A note about the following code: I do not use numbering for headings in my real document, but I applied the solution to that use case as well. Which is why I am a bit skeptical to mark this question as solved. I suppose I will leave it unsolved for a week or so and hope some of you might chime in with some hints. If not, that is ok too. :)

Edit 2021-03-17-2303 (CET)

One side-effect with secnumdepth > 0 is an ugly TOC entry as KOMA somehow does not use its TOC styling for the string which is provided to the sectioning command. In the MWE below, this would be Heading with quite. This looks quite awful, which is why I should and will not mark this reply as the solution for my question.

Screenshot for secnumdepth = 0

enter image description here

Screenshot for secnumdepth > 0

enter image description here

MWE

So the corresponding and enhanced MWE for my currently working solution is:

\documentclass[
11pt,
a4paper,
parskip=false-
]
{scrartcl}

\usepackage{
lmodern,
blindtext,
tikz,
multicol,
etoolbox,
calc,
tikzpagenodes,
}

\usetikzlibrary{calc}

\usepackage[
pdfencoding=auto,
]{hyperref}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\RedeclareSectionCommands[
    beforeskip=0pt,
    afterskip=3pt,
    tocentryformat=\small,
    toclinefill=\small\TOCLineLeaderFill,
    tocpagenumberformat=\small,
%   addtokomafont=\Large
]{subsection}
\addtokomafont{subsection}{\Large}

%\setcounter{secnumdepth}{0}

%=================================
% hide section headings - circumvent with fake heading
%src: https://tex.stackexchange.com/a/129985/25683
%=================================
\newcommand{\myownsec}[1]{%
  \par\refstepcounter{section}% Increase section counter
  \sectionmark{#1}% Add section mark (header)
%  \addcontentsline{toc}{section}{\protect\numberline{\thesection}#1}% Add section to ToC
  \addcontentsline{toc}{section}{#1}% Add section to ToC
  % Add more content here, if needed.
}

%***********************************************************
%***********************************************************
%  NEW version
%***********************************************************
%***********************************************************
\newlength{\randomlength}

\newrobustcmd{\specialthing}[1]{%
\setlength{\randomlength}{\widthof{\thesection}}
\texorpdfstring{%
\begin{tikzpicture}
    \node[
        inner sep=0pt,
        outer sep=1pt,
        anchor=south west,
        align=left,
%       text width=\columnwidth, % <----- perfect if secnumdepth=0
        text width=\columnwidth-\randomlength-1.1em, % <------- this is preferrable if the counter secnumdepth is higher than 0 (or whichever number equals the sectioning depth of the commands you intend to use this tikz "add-on" with)
    ] (sectionnode) {#1};
    \draw[semithick, orange] ($(sectionnode.north west -| current page text area.west)+(-0.5\columnwidth,2pt)$) -- ($(sectionnode.north east)+(0,2pt)$) -- ($(sectionnode.south east)+(0,-2pt)$); % <------- this is preferrable if the counter secnumdepth is higher than 0 (or whichever number equals the sectioning depth of the commands you intend to use this tikz "add-on" with)
%   \draw[semithick, orange] ($(sectionnode.north west)+(0,2pt)$) -- ($(sectionnode.north east)+(0,2pt)$) -- ($(sectionnode.south east)+(0,-2pt)$); % <----- perfect if secnumdepth=0
\end{tikzpicture}}{#1}}


\usepackage[showframe]{geometry}

\listfiles
\begin{document}
\begin{multicols*}{2}

\myownsec{Word}

\section{\specialthing{Heading with quite}}

\subsection{Heading with words and such}

\section{\specialthing{And way more words in this heading}}

\blindtext[1]

\blindtext[1]

\blindtext[1]


\end{multicols*}
\end{document}

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.