2

So I tried to make underlined-centered titles:
The answer for the centered came here and here.

Now my question is, how I make it underlined: with \ul it doesn't work (the file don't compile, and with uline I get ugly underline:
enter image description here

And here is the MWE:

\documentclass{scrartcl}

\usepackage{fontspec,adforn,ulem,soul}

\makeatletter

\addtokomafont{section}{\centering}  
\addtokomafont{subsection}{\centering}
\renewcommand{\sectionlinesformat}[4]{%
    %\@tempswafalse
        \ifstr{#1}{section}{%
                {\@hangfrom{{{#3}{#4}\adforn{12}}}}
        }
        {\ifstr{#1}{subsection}{%
                {\@hangfrom{\uline{{{#3}{#4}\adforn{24}}}}}%
        }
    {\@hangfrom{\hskip#2#3}{#4}}}%
}\makeatother

\begin{document}

\part{ABC}

\section{abc}

\subsection{abcd efgh abcd efgh iiii hhjjgghgg abcd efgh abcd efgh iiii hhjjgghgg abcd efgh abcd efgh iiii hhjjgghgg}
\end{document}

P.S. For the parts I got answer here but it also don't work.
and here is about using \ul or \uline.
And if I'm putting parbox this what I get:
enter image description here and this is the relevant line:

{\ifstr{#1}{subsection}{%
                {\@hangfrom{\uline{\parbox{\linewidth}{{#3}{#4}\adforn{24}}}}}%
        }

Do you have any idea how it could work and look properly and the text can be more then one line centered and underlined?

Thank you!!

  • 1
    Your usage of \@hangfrom is wrong and does not make sense. Do you known, what it does? You should remove it and several of the brace-pairs too. Off-topic: Underlining is ugly and AFAIK there are no perfect solutions to do it with LaTeX. – Schweinebacke Mar 15 at 20:53
  • @Schweinebacke, I will remove it, I take it from KOMA-script manual. And why there is no solution? can you think about something do similar? Thanks! – heblyx Mar 15 at 20:58
  • 2
    All underlines are ugly. If you don't have to underline, don't do it. – Uwe Ziegenhagen Mar 15 at 21:10
2

To visualize the problems with underlining in your case please see the following code. It is based on my answer and uses underlining with command \ul{} from package soul. Please see also that your used \adforn{} is placed in the title for section and subsection:

\documentclass{scrartcl}

\usepackage{fontspec,adforn}
\usepackage{soul}


\begin{document}

\renewcommand\raggedsection{\centering}

\part{ABC}

\section{\ul{abc test test test test test test test test test test test test 
  test test test test test test test test test test test test test test 
  test test test test test test} \adforn{12}} % <=======================

\subsection{\ul{def} \adforn{24}} % <===================================

\section{\ul{abc test test test test test test test test test test test test 
  test test test test test test test test test test test test test test 
  test test test test test test \protect\adforn{12}}} % <===============
\end{document} 

with the result:

enter image description here

As you can see \ul{...} is able to underline long text inside a \section if the \adforn{} is not included to \ul (see first red circle in image above)!

Now you can try to include \adforn into \ul like

\subsection{\ul{def \adforn{24}}}

with the result of 9 errors.

As you can see marked with the second red circle in the image above you can use \protect\adfarn to be able to compile without errors but the result is ugly (second red circle).

Conclusion:

  • You can have underlining with centering without using \adforn or
  • you can use \adforn with centering but without underlining

I suggest to omit underlining!

Based on the second MWE in this answer you can do

\documentclass{scrartcl}

\usepackage{fontspec}
\usepackage{adforn}
\usepackage{soul} % <===================================================

\renewcommand\raggedsection{\centering}

\let\originalsectionlinesformat\sectionlinesformat
\renewcommand{\sectionlinesformat}[4]{%
  \originalsectionlinesformat{#1}{#2}{#3}{\ul{#4}% <====================
    \ifstr{#1}{section}{\adforn{12}}
      {\ifstr{#1}{subsection}{\adforn{24}}{}}%
  }%
}

\usepackage{blindtext}% only for dummy text
\begin{document}
\section{abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc}
\blindtext
\subsection{def}
\blindtext
\end{document}

to get underlining heading for \section and \subsection without automaticly added \adforn symbol. But see: that could result in ugly typography, depending on the content of the used heading text ...

  • Thank you for your answer! But if I want that the adforn symbols will be part of the title automatically, and not manually, can I do it? Or it's a problem? (because as you can see, it was at the MWE...) Thank you!! – heblyx Mar 15 at 21:48
  • 1
    @heblyx see the second mwe of the answer here: tex.stackexchange.com/a/479683/16550 ... But be careful: Things can go wrong if the headings for section and subsection contains non-ascii-letters, they can result simular errors \adforn does ... You want to force underlining, but believe me (and the others telling you) it is a bad idea. – Kurt Mar 15 at 21:52
  • Saw it... So I can make only the text (without the adforn) underlined? (and centered of course...) – heblyx Mar 15 at 21:54
  • It's possible?? – heblyx Mar 15 at 23:40
  • Yes... This what I tried right now but it's still not working :-( It's still one long line.... Do you not what can I do?? Thank you!! – heblyx Mar 16 at 0:21

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.