1

I'm preparing my document (Koma-script report class) in Lyx.

If I use \KOMAoptions{headings=onelinechapter} the chapter has no prefix

Without it the MWE produces the file with chapter prefix + title in two lines.

 \documentclass[fontsize=13pt]{scrreprt}
\usepackage{fontspec}

\makeatletter %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% User specified LaTeX commands. \RequirePackage{fix-cm} \usepackage{fontspec} \setmainfont{Cambria} \usepackage[english, russian]{babel} %\usepackage[fontsize=13pt]{scrextend} \usepackage {setspace} \onehalfspacing \usepackage[a4paper, left=2.5cm, right=1cm, top=2cm, nohead]{geometry}

\addtokomafont{disposition}{\rmfamily} \KOMAoption{chapterprefix}{true} \KOMAoptions{headings=onelinechapter}

\setkomafont{chapter}{\MakeUppercase} \setkomafont{chapter}{\rmfamily\mdseries} \setkomafont{section}{\rmfamily\mdseries}

\usepackage{mathtext} %\usepackage[backend=biber, style=gost-numeric, bibencoding=utf8, sorting=none, language=auto]{biblatex} %\usepackage{multirow} %\usepackage{longtable}

\ifpdf\usepackage{graphicx}\else\usepackage{graphicx}\fi

\usepackage{comment}

%\ifpdf\usepackage{epstopdf}\usepackage{pdfpages}\fi

\graphicspath{{fig/}}

\renewcommand{\appendixfont}{\normalsize\bfseries}

\setcounter{tocdepth}{2}

\makeatother

\usepackage[style=gost-numeric,backend=biber, style=gost-numeric, bibencoding=utf8, sorting=none, language=auto]{biblatex}

\begin{document} \tableofcontents \clearpage

\chapter*{{\large{}Введение}}
\addcontentsline{toc}{chapter}{Введение}

\chapter{\textsc{\large{}Литературный обзор}}

\vspace{40pt}
\section{{\normalsize{}один}}
\section{{\normalsize{}два}}

\chapter{\textsc{\large{}Технология приготовления }}
\vspace{40pt}

\section{{\normalsize{}один}} \section{еще}

\chapter*{{\large{}Литература}} \end{document}

I'd like to keep the prefix , but on the same line and also with dot after it.

Like "Глава 1. ЛИТЕРАТУРНЫЙ ОБЗОР"

How is that done? I believe \chapterlineswithprefixformat commands should be used somehow, but not sure.

cabohah
  • 11,455

1 Answers1

2

There are several things in your code, you should not do, e.g., adding font size commands to the argument of \chapter and \section. KOMA-Script provides a user interface for clean changing of fonts. Please use it.

Package fix-cm does not make sense, when using LuaLaTeX and XeLaTeX. With fontspec the default font is already the OTF version of Latin Modern. fix-cm is for legacy European Computer Modern and legacy Computer Modern. So it makes sense with PDFLaTeX only.

Note: \MakeUppercase is not a font switching command in sense of KOMA-Script. So you should not use it as argument of \setkomafont. See the KOMA-Script manuals for more information about \setkomafont. In your case the \setkomafont{chapter}{\MakeUppercase} is completely useless, because the next \setkomfont{chapter}{…} overwrites and therefore deactivate the usage of \MakeUppercase.

You should not load packages more than once. I know, that it works, if the options are the same (and with some package even if not), but with the next change of options or used packages it may fail. So just don't do it.

Don't use random \makeatletter and \makeatother. Use them where needed only.

Also you should not use \vspace{…} after headings. KOMA-Script provides a user interface to change the spacing before and after headings. Please use it.

To change the format of the numbers of headings, KOMA-Script provides commands like \chapterformat, \sectionformat etc. So an IMHO better (and minimized) code would be be:

\documentclass[fontsize=13pt,headings=nochapterprefix]{scrreprt}
\usepackage{fontspec}
\usepackage{libertine}%\setmainfont{Cambria}% Sorry, Cambria is not a font of TeX Live. Please reactivate the font yourself
\usepackage[english, russian]{babel}
\usepackage[onehalfspacing]{setspace}
\usepackage[a4paper, left=2.5cm, right=1cm, top=2cm, nohead]{geometry}

\addtokomafont{disposition}{\rmfamily} \renewcommand*{\chapterformat}{\chapapp~\thechapter.\enskip}% or maybe % \autodot instead of the hard coded "."

\setkomafont{sectioning}{}% don't use \sffamily\bfseries %\setkomafont{chapter}{\MakeUppercase}% \MakeUppercase is not a font command % and does not really make sense, when using \scshape \setkomafont{chapter}{\large}% change size \setkomafont{section}{\normalsize}% change size

\RedeclareSectionCommand[afterskip=74pt plus 2.25pt minus 3.75pt]{chapter}% increase space after chapter

\begin{document} \tableofcontents

\addchap{Введение}

\addtokomafont{chapter}{\scshape}% Why not already in the preamble and % therefor also for the \addchap chapter? \chapter{Литературный обзор}

\section{один} \section{два}

\chapter{Технология приготовления}

\section{один} \section{еще}

\chapter*{Литература} \end{document}

enter image description here

If you really want the \MakeUppercase, you can add something like:

\renewcommand{\chapterlinesformat}[3]{%
  \MakeUppercase{#2#3}%
}

or

\renewcommand{\chapterlinesformat}[3]{%
  #2\MakeUppercase{#3}%
}

or

\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
  \@hangfrom{\MakeUppercase{#2}{\MakeUppercase{#3}}%
}
\makeatother

or

\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
  \@hangfrom{#2}{\MakeUppercase{#3}}%
}
\makeatother

to the document preamble.

If you want to add the chapter prefix also to the chapter entries in the page header, e.g, of page style headings, see \chaptermarkformat in the KOMA-Script manuals.

cabohah
  • 11,455
  • Thank you for explaining these points! I should say libertine font didn't work out and Cambria did - because of OS, I guess. Did you mean should not load Koma-scrirt "more than once"? @cabohah – Alexandra Mar 12 '24 at 23:44
  • @Alexandra See in your example. You are loading fontspec twice. Libertine is free and available in TeX Live and MiKTeX. It is suitable for my example (see the resulting screenshot). So I've used it. Cambria is a Microsoft font not available for free with TeX Live or Linux. So it is not the best idea for a minimal working example, and I cannot use it, because I'm not using Windows. BTW: For your problem even using russian and a Cyrillic font is not needed. It is the same with a Latin font. – cabohah Mar 13 '24 at 08:03