自动插入/在章节之前

自动插入/在章节之前

我的乳胶代码有问题:

\documentclass[fontsize=8.5pt,DIV=calc]{scrbook}
\usepackage{fix-cm}

\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[scaled]{helvet}

\usepackage{geometry} 
\geometry{a4paper,left=15mm,right=15mm, top=26mm, bottom=17mm} 
\renewcommand{\familydefault}{\sfdefault}

\usepackage{multicol} 
\usepackage{multirow}

\usepackage[letterspace=30]{microtype} 
\linespread{1.13} 
\newlength{\sectionbaselineskip}
\setlength{\sectionbaselineskip}{\baselineskip}

\usepackage{tocloft}
\usepackage{amssymb}
\usepackage{mdframed}
\usepackage{rotating}

\definecolor{SectionGray}{gray}{0.85}

\newenvironment{JustLeft}[1][\textwidth]
{\begin{minipage}[t]{#1}\begin{flushleft}}
{\end{flushleft}\end{minipage}}

\newenvironment{col}
{\raggedcolumns%
\begin{multicols}{2}%
\setlength{\parskip}{1\baselineskip}%
\setlength{\parindent}{0pt}%
\setlength{\parsep}{0pt}%
}
{\end{multicols}}

\renewcommand\familydefault{\sfdefault}
\renewcommand{\labelitemi}{\textcolor{black!60}{\raisebox{0.5mm}{\rule{1.8mm}{1.8mm}}}}
\newcommand{\zitiert}[1]{\flqq{#1}\frqq}

\usepackage{enumitem}
\setitemize{leftmargin=*}

% Chapter
% -------
\addtokomafont{chapter}{\fontsize{12pt}{\sectionbaselineskip}\selectfont}
\renewcommand*{\chapterheadstartvskip}{\vspace*{-10.5mm}} 
\renewcommand*{\chapterheadendvskip}{\vspace{6.5mm}} 
\setlength{\cftbeforechapskip}{0pt}
\renewcommand{\cftchapafterpnum}{\vskip11.5pt}

% Section
% -------
\setkomafont{section}{\fontsize{10pt}{\sectionbaselineskip}\selectfont}
\setkomafont{subsection}{\fontsize{8.5pt}{\sectionbaselineskip}\selectfont}
\setkomafont{subsubsection}{\fontsize{8.5pt}{\sectionbaselineskip}\selectfont}
%\setlength{\cftbeforesecskip}{3ex}
\setlength{\cftsecindent}{0ex}
\setlength{\cftsecnumwidth}{3ex}
\renewcommand{\cftsecafterpnum}{\vskip11.5pt}

\newlength{\secboxlen}
\newlength{\sectextlen}
\newcounter{mylinecounter}
\setlength{\fboxsep}{0pt}

\newcommand{\SectionKopf}{\rule{0pt}{2.4ex}}
\newcommand{\SectionFuss}{\rule[-1.1ex]{0pt}{1ex}}

\newcommand{\TheSection}[3][n]{%
%           ===========
\setlength{\secboxlen}{\linewidth}%
\addtolength{\secboxlen}{-2\fboxsep}%
\setlength{\sectextlen}{\linewidth}%
\addtolength{\sectextlen}{-1cm}%
\stepcounter{section}%
\makebox[0pt][l]{%
\raisebox{0pt}[0pt][0pt]{%
\colorbox{SectionGray}{%
\begin{JustLeft}[\secboxlen]%
\fontsize{10pt}{\sectionbaselineskip}\selectfont%
\makebox[1mm]{}\bfseries\makebox[9mm][l]{\thesection}%
\begin{JustLeft}[\sectextlen]%
{\SectionKopf#3\SectionFuss}%
\end{JustLeft}%
\end{JustLeft}}%
}%
}%
\ifthenelse{\equal{#1}{b}}
{% IF
\addtocontents{toc}{\protect\renewcommand{\cftsecpagefont}{\bfseries}}%
\addcontentsline{toc}{section}{\bfseries\numberline{\thesection}#3}%
\addtocontents{toc}{\protect\renewcommand{\cftsecpagefont}{\mdseries}}%
}%
{% ELSE
\addcontentsline{toc}{section}{\numberline{\thesection}#3}%
}%
\par%
\setcounter{mylinecounter}{1}%
\whiledo{\value{mylinecounter}<#2}{\nothing\\\stepcounter{mylinecounter}}%
}


\newcommand{\chapterend}{%
%           ========
\\[2\baselineskip]%
}

\begin{document}

\chapter*{2018 FIFA World Cup}

\begin{col}
\TheSection{1}{Budget}
At an estimated cost of over 14.2 billion as of June 2018, it is the most expensive World Cup in history, surpassing the cost of the 2014 FIFA World Cup in Brazil.

The Russian government had originally earmarked a budget of around 20 billion which was later slashed to 10 billion for the preparations of the World Cup, of which half is spent on transport infrastructure. As part of the program for preparation to the 2018 FIFA World Cup, a federal sub-program "Construction and Renovation of Transport Infrastructure" was implemented with a total budget of 352.5 billion rubles, with 170.3 billion coming from the federal budget, 35.1 billion from regional budgets, and 147.1 billion from investors. The biggest item of federal spending was the aviation infrastructure (117.8 billion rubles). Construction of new hotels was a crucial area of infrastructure development in the World Cup host cities. Costs continued to balloon as preparations were underway.\chapterend
%
\TheSection{1}{Infrastructure spending}
Platov International Airport in Rostov-on-Don was upgraded with automated air traffic control systems, modern surveillance, navigation, communication, control, and meteorological support systems. Koltsovo Airport in Yekaterinburg was upgraded with radio-engineering tools for flight operation and received its second runway strip. Saransk Airport received a new navigation system; the city also got two new hotels, Mercure Saransk Centre (Accor Hotels) and Four Points by Sheraton Saransk (Starwood Hotels) as well as few other smaller accommodation facilities. In Samara, new tram lines were laid.] Khrabrovo Airport in Kaliningrad was upgraded with radio navigation and weather equipment.Renovation and upgrade of radio-engineering tools for flight operation was completed in the airports of Moscow, Saint Petersburg, Volgograd, Samara, Yekaterinburg, Kazan and Sochi. On 27 March, the Ministry of Construction Industry, Housing and Utilities Sector of Russia reported that all communications within its area of responsibility have been commissioned. The last facility commissioned was a waste treatment station in Volgograd. In Yekaterinburg, where four matches are hosted, hosting costs increased to over 7.4 billion rubles, over-running the 5.6 billion rubles originally allocated from the state and regional budget.\chapterend
%
\TheSection{1}{Volunteers}
Volunteer applications to the Russia 2018 Local Organising Committee opened on 1 June 2016. The 2018 FIFA World Cup Russia Volunteer Program received about 177,000 applications, and engaged a total of 35,000 volunteers. They received training at 15 Volunteer Centres of the Local Organising Committee based in 15 universities, and in Volunteer Centres in the host cities. Preference, especially in the key areas, was given to those with knowledge of foreign languages and volunteering experience, but not necessarily to Russian nationals.\chapterend
%
\TheSection{1}{Transport}
Free public transport services were offered for ticketholders during the World Cup.
\chapterend
%
\TheSection{1}{Schedule}
The full schedule was announced by FIFA on 24 July 2015 (without kick-off times, which were confirmed later). On 1 December 2017, following the final draw, six kick-off times were adjusted by FIFA.
Russia was placed in position A1 in the group stage and played in the opening match at the Luzhniki Stadium in Moscow on 14 June against Saudi Arabia, the two lowest ranked teams of the tournament at the time of the final draw.The Luzhniki Stadium also hosted the second semi-final on 11 July and the final on 15 July. The Krestovsky Stadium in Saint Petersburg hosted the first semi-final on 10 July and the third place play-off on 14 July.

\newpage
\end{col}
\end{document}

不幸的是,MWE 并不是真正最小的 :( 我希望有人能帮助我。使用这个代码我得到了类似 在此处输入图片描述

我想自动在“0.5 时间表”部分之前进行分栏(不在\columnbreak文档中)。我猜有一种方法可以使用序言中的一些代码来解决这个问题,但我不知道该怎么做。

答案1

我不确定你的代码风格(布局可能没问题,但你使用的 TeX 代码...)。无论如何,你可以\nopagebreak在宏的末尾添加\TheSection

\documentclass[fontsize=8.5pt,DIV=calc]{scrbook}
\usepackage{fix-cm}

\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage[scaled]{helvet}

\usepackage{geometry} 
\geometry{a4paper,left=15mm,right=15mm, top=26mm, bottom=17mm} 
\renewcommand{\familydefault}{\sfdefault}

\usepackage{multicol} 
\usepackage{multirow}

\usepackage[letterspace=30]{microtype} 
\linespread{1.13} 
\newlength{\sectionbaselineskip}
\setlength{\sectionbaselineskip}{\baselineskip}

\usepackage{tocloft}
\usepackage{amssymb}
\usepackage{mdframed}
\usepackage{rotating}

\definecolor{SectionGray}{gray}{0.85}

\newenvironment{JustLeft}[1][\textwidth]
{\begin{minipage}[t]{#1}\begin{flushleft}}
{\end{flushleft}\end{minipage}}

\newenvironment{col}
{\raggedcolumns%
\begin{multicols}{2}%
\setlength{\parskip}{1\baselineskip}%
\setlength{\parindent}{0pt}%
\setlength{\parsep}{0pt}%
}
{\end{multicols}}

\renewcommand\familydefault{\sfdefault}
\renewcommand{\labelitemi}{\textcolor{black!60}{\raisebox{0.5mm}{\rule{1.8mm}{1.8mm}}}}
\newcommand{\zitiert}[1]{\flqq{#1}\frqq}

\usepackage{enumitem}
\setitemize{leftmargin=*}

% Chapter
% -------
\addtokomafont{chapter}{\fontsize{12pt}{\sectionbaselineskip}\selectfont}
\renewcommand*{\chapterheadstartvskip}{\vspace*{-10.5mm}} 
\renewcommand*{\chapterheadendvskip}{\vspace{6.5mm}} 
\setlength{\cftbeforechapskip}{0pt}
\renewcommand{\cftchapafterpnum}{\vskip11.5pt}

% Section
% -------
\setkomafont{section}{\fontsize{10pt}{\sectionbaselineskip}\selectfont}
\setkomafont{subsection}{\fontsize{8.5pt}{\sectionbaselineskip}\selectfont}
\setkomafont{subsubsection}{\fontsize{8.5pt}{\sectionbaselineskip}\selectfont}
%\setlength{\cftbeforesecskip}{3ex}
\setlength{\cftsecindent}{0ex}
\setlength{\cftsecnumwidth}{3ex}
\renewcommand{\cftsecafterpnum}{\vskip11.5pt}

\newlength{\secboxlen}
\newlength{\sectextlen}
\newcounter{mylinecounter}
\setlength{\fboxsep}{0pt}

\newcommand{\SectionKopf}{\rule{0pt}{2.4ex}}
\newcommand{\SectionFuss}{\rule[-1.1ex]{0pt}{1ex}}

\newcommand{\TheSection}[3][n]{%
%           ===========
\setlength{\secboxlen}{\linewidth}%
\addtolength{\secboxlen}{-2\fboxsep}%
\setlength{\sectextlen}{\linewidth}%
\addtolength{\sectextlen}{-1cm}%
\stepcounter{section}%
\makebox[0pt][l]{%
\raisebox{0pt}[0pt][0pt]{%
\colorbox{SectionGray}{%
\begin{JustLeft}[\secboxlen]%
\fontsize{10pt}{\sectionbaselineskip}\selectfont%
\makebox[1mm]{}\bfseries\makebox[9mm][l]{\thesection}%
\begin{JustLeft}[\sectextlen]%
{\SectionKopf#3\SectionFuss}%
\end{JustLeft}%
\end{JustLeft}}%
}%
}%
\ifthenelse{\equal{#1}{b}}
{% IF
\addtocontents{toc}{\protect\renewcommand{\cftsecpagefont}{\bfseries}}%
\addcontentsline{toc}{section}{\bfseries\numberline{\thesection}#3}%
\addtocontents{toc}{\protect\renewcommand{\cftsecpagefont}{\mdseries}}%
}%
{% ELSE
\addcontentsline{toc}{section}{\numberline{\thesection}#3}%
}%
\par%
\setcounter{mylinecounter}{1}%
\whiledo{\value{mylinecounter}<#2}{\nothing\\\stepcounter{mylinecounter}}%
\nopagebreak%
}


\newcommand{\chapterend}{%
%           ========
\\[2\baselineskip]%
}

\begin{document}

\chapter*{2018 FIFA World Cup}

\begin{col}
\TheSection{1}{Budget}
At an estimated cost of over 14.2 billion as of June 2018, it is the most expensive World Cup in history, surpassing the cost of the 2014 FIFA World Cup in Brazil.

The Russian government had originally earmarked a budget of around 20 billion which was later slashed to 10 billion for the preparations of the World Cup, of which half is spent on transport infrastructure. As part of the program for preparation to the 2018 FIFA World Cup, a federal sub-program "Construction and Renovation of Transport Infrastructure" was implemented with a total budget of 352.5 billion rubles, with 170.3 billion coming from the federal budget, 35.1 billion from regional budgets, and 147.1 billion from investors. The biggest item of federal spending was the aviation infrastructure (117.8 billion rubles). Construction of new hotels was a crucial area of infrastructure development in the World Cup host cities. Costs continued to balloon as preparations were underway.\chapterend
%
\TheSection{1}{Infrastructure spending}
Platov International Airport in Rostov-on-Don was upgraded with automated air traffic control systems, modern surveillance, navigation, communication, control, and meteorological support systems. Koltsovo Airport in Yekaterinburg was upgraded with radio-engineering tools for flight operation and received its second runway strip. Saransk Airport received a new navigation system; the city also got two new hotels, Mercure Saransk Centre (Accor Hotels) and Four Points by Sheraton Saransk (Starwood Hotels) as well as few other smaller accommodation facilities. In Samara, new tram lines were laid.] Khrabrovo Airport in Kaliningrad was upgraded with radio navigation and weather equipment.Renovation and upgrade of radio-engineering tools for flight operation was completed in the airports of Moscow, Saint Petersburg, Volgograd, Samara, Yekaterinburg, Kazan and Sochi. On 27 March, the Ministry of Construction Industry, Housing and Utilities Sector of Russia reported that all communications within its area of responsibility have been commissioned. The last facility commissioned was a waste treatment station in Volgograd. In Yekaterinburg, where four matches are hosted, hosting costs increased to over 7.4 billion rubles, over-running the 5.6 billion rubles originally allocated from the state and regional budget.\chapterend
%
\TheSection{1}{Volunteers}
Volunteer applications to the Russia 2018 Local Organising Committee opened on 1 June 2016. The 2018 FIFA World Cup Russia Volunteer Program received about 177,000 applications, and engaged a total of 35,000 volunteers. They received training at 15 Volunteer Centres of the Local Organising Committee based in 15 universities, and in Volunteer Centres in the host cities. Preference, especially in the key areas, was given to those with knowledge of foreign languages and volunteering experience, but not necessarily to Russian nationals.\chapterend
%
\TheSection{1}{Transport}
Free public transport services were offered for ticketholders during the World Cup.
\chapterend
%
\TheSection{1}{Schedule}
The full schedule was announced by FIFA on 24 July 2015 (without kick-off times, which were confirmed later). On 1 December 2017, following the final draw, six kick-off times were adjusted by FIFA.
Russia was placed in position A1 in the group stage and played in the opening match at the Luzhniki Stadium in Moscow on 14 June against Saudi Arabia, the two lowest ranked teams of the tournament at the time of the final draw.The Luzhniki Stadium also hosted the second semi-final on 11 July and the final on 15 July. The Krestovsky Stadium in Saint Petersburg hosted the first semi-final on 10 July and the third place play-off on 14 July.

\newpage
\end{col}
\end{document}

在此处输入图片描述

相关内容