如何刪除 KOMA-Script 部分標題中的空格

如何刪除 KOMA-Script 部分標題中的空格

這是 MWE:

\documentclass{scrartcl}
\usepackage{adforn}


\renewcommand{\sectionlinesformat}[4]{%
        \ifstr{#1}{section}{%
               {\adforn{30} {#3}. {#4} \adforn{58}}
        }
    {{\hskip#2#3}{#4}}%
}\makeatother

\begin{document}

\section{ABC}

\end{document} 

輸出是這樣的:
在此輸入影像描述

我希望它會是:1.ABC並不是1. ABC (「1」和「.」之間沒有空格)
有可能的?如果可能的話,我該怎麼做?

謝謝你!

答案1

該巨集末尾\sectionformat包含一個。\enskip沒有這個你可以重新定義它:

\documentclass{scrartcl}
\usepackage{adforn}

\def\sectionformat{\thesection\autodot}% \enskip
\renewcommand{\sectionlinesformat}[4]{%
        \ifstr{#1}{section}{%
               {\adforn{30} {#3}. {#4} \adforn{58}}
        }
    {{\hskip#2#3}{#4}}%
}\makeatother

\begin{document}

\section{ABC}

\end{document}

在此輸入影像描述

答案2

您應該將組大括號減少到最低限度,並將.其中一個添加到\sectionformat

\documentclass{scrartcl}
\usepackage{adforn}

\renewcommand*{\sectionformat}{\thesection.\enskip}% replaced \autodot by .
\renewcommand{\sectionlinesformat}[4]{%
  \ifstr{#1}{section}%
    {\adforn{30} #3#4 \adforn{58}}%
    {\hskip#2#3#4}%
}\makeatother

\begin{document}

\section{ABC}

\end{document} 

或選擇numbers=withdot將點新增至所有部分層級:

\documentclass[numbers=enddot]{scrartcl}
\usepackage{adforn}

\renewcommand{\sectionlinesformat}[4]{%
  \ifstr{#1}{section}%
    {\adforn{30} #3#4 \adforn{58}}%
    {\hskip#2#3#4}%
}

\begin{document}

\section{ABC}

\end{document} 

這兩個例子的結果是:

O 1. ABC o

注意:您不應將\autodotin\sectionformat與硬編碼結合.(無論是在規範中錯誤放置的位置\autodot還是在\sectionlinesformat其位置上),因為這可能會導致兩個點出現。

請查看KOMA-Script 手冊的預設值以及、和\sectionformat的意義。numbers=withdot\sectionformat\autodot

順便說一句:\makeatother您的範例中的 也不是必需的,應該刪除(所以我這樣做了)。

題外話:您也應該避免在程式碼中間透過換行符}或真實空格來避免可能出現的虛假空格。{


正如評論聲稱這不適用於hebrew

\documentclass[numbers=enddot]{scrartcl}
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{David CLM}
\newfontfamily\hebrewfonttt[Script=Hebrew]{Miriam Mono CLM}
\newfontfamily\hebrewfontsf[Script=Hebrew]{Simple CLM}
\usepackage{adforn}

\renewcommand{\sectionlinesformat}[4]{%
  \ifstr{#1}{section}%
    {\adforn{30} #3#4 \adforn{58}}%
    {\hskip#2#3#4}%
}

\begin{document}

\section{גדה}

\end{document} 

\documentclass{scrartcl}
\usepackage{polyglossia}
\setmainlanguage{hebrew}
\newfontfamily\hebrewfont[Script=Hebrew]{David CLM}
\newfontfamily\hebrewfonttt[Script=Hebrew]{Miriam Mono CLM}
\newfontfamily\hebrewfontsf[Script=Hebrew]{Simple CLM}
\usepackage{adforn}

\renewcommand*{\sectionformat}{\thesection.\enskip}% replaced \autodot by .
\renewcommand{\sectionlinesformat}[4]{%
  \ifstr{#1}{section}%
    {\adforn{30} #3#4 \adforn{58}}%
    {\hskip#2#3#4}%
}

\begin{document}

\section{גדה}

\end{document} 

兩者都會導致:

o הדג .1 O

這對於使用 RL 來說似乎是正確的。

相關內容