セクションの前後のスペース

セクションの前後のスペース

テキスト内に段落間のスペースが追加されました [画像を参照]。さらに、スペースのサイズが異なります。さらに、セクションの前とセクション タイトルの後にも追加のスペースがあります。また、セクション タイトルによってサイズが異なります。 ここに画像の説明を入力してください ここに画像の説明を入力してください ここに画像の説明を入力してください これを修正するにはどうすればよいでしょうか。

    \documentclass[openany]{book}
    \usepackage[utf8]{inputenc}
    \usepackage[MeX]{polski}
    \usepackage{xcolor}
    \usepackage{lipsum}
    \usepackage[explicit]{titlesec}
    \usepackage[dotinlabels]{titletoc}
    \usepackage{setspace}
    \onehalfspacing
    \usepackage[protrusion=true,expansion=true]{microtype}
    \usepackage{lettrine}
    \usepackage{titlesec}
    %\titleformat{\section}{\normalfont\bfseries}{\thesection}{1em}{}
    %\linespread{0.9}
    \newlength\BoxWd
    \setlength\BoxWd{0.75cm}
    \newlength\Aux
    \usepackage[left=4.65cm, right=4.65cm, top=4cm, bottom=4.25cm]{geometry}

    % chapter tiltes formatting
    \titleformat{\chapter}[display]
     {\normalfont\sffamily\huge}
     {\renewcommand{\thechapter}{\Roman{chapter}}%
      \settowidth\Aux{\textcolor{white}{\Huge\thechapter}}
      \ifnum\Aux>\BoxWd
        \setlength\BoxWd{\Aux}
      \else\fi
     \hspace*{0.3em}\colorbox{black}{%
     \parbox[c][1.2cm][c]{\BoxWd}{%
      \centering\textcolor{white}{\Huge\thechapter}}}}
      {-1ex}
      {\titlerule\vspace{.7ex}\filleft\MakeUppercase{#1}}
      [\vspace{.2ex}\titlerule]
     \titlespacing*{\chapter}{0pt}{50pt}{80pt}
     \titleformat{\section}
      {\scshape\normalsize\bfseries}{\MySecSquare\ \thesection.}{0.15em}{#1}
       \titlespacing*{\section}{0pt}{2.5pt}{1.5pt}

       \titleformat{\subsection}
       {\normalfont\scshape\normalsize\bfseries}{\MySecSquare\ \thesubsection.} {0.10em}{#1}
      \titlespacing*{\subsection}{0pt}{1.5pt}{0.5pt}

      % formatting for chapter entries in ToC  
      \titlecontents{chapter}
      [3em]{\vspace*{5.5pt}}
      {\small\bfseries{\hspace*{-2.63em}{\chaptername}\hspace*  {5pt}\contentslabel{0.25em}\hspace*{1.25em}}}
      {\hspace*{-3em}}
      {\titlerule*[1pc]{.}\small\sffamily\bfseries\contentspage}

      % formatting for section entries in ToC  
      \titlecontents{section}
      [4em]{\vspace*{-2pt}}
      {\small\contentslabel{2.5em}}
      {\hspace*{2.75em} }%\hspace*{-2.3em}
      {\titlerule*[1pc]{.}\small\sffamily\contentspage}

      \titlecontents{subsection}
      [7em]{\vspace*{-2pt}}
      {\small\contentslabel{2.85em}}
      {\hspace*{6em}}
      {\titlerule*[1pc]{.}\small\sffamily\contentspage}

      \newcommand\MySquare{%
      \leavevmode\hbox to 1.2ex{\hss\vrule height .9ex width .7ex depth -.2ex\hss}}

      \newcommand\MySecSquare{%
      \leavevmode\hbox to 1.2ex{\hss\vrule height 1.3ex width 1.1ex depth -.2ex\hss}}

      \renewcommand\labelitemi{\MySquare}

      \newenvironment{myquote}{\list{}{\leftmargin=15pt\rightmargin=0.0pt}\item[]}{\endlist}
      \newcommand\MyTitle{Some title}
      \usepackage{fancyhdr}
      \fancyhf{}
      \fancyhead[EL,OR]{\thepage}
      \fancyhead[OL]{\scriptsize\scshape{\leftmark}}
      \fancyhead[ER]{\footnotesize\scshape{\MyTitle}}
      \renewcommand\headrulewidth{0.2pt}


      \pagestyle{fancy}

      \newcommand{\initial}[1]{%
        \lettrine[lines=2,lhang=0.35,nindent=0em]{
                    \color{black}
                    {{#1}}}{}}
       \renewcommand\chaptermark[1]{\markboth{\thechapter.\ #1}{}} 
        \usepackage{hyperref}
       \hypersetup
        {   
        colorlinks,
        citecolor=black,
        filecolor=black,
        linkcolor=black,
        urlcolor=black,
        pdfauthor = {Pdfautor},
        pdftitle = {My title},
        pdftex
         }

         \begin{document}

        \frontmatter

        \tableofcontents
        \clearpage

        \newpage
        \thispagestyle{empty}



        \mainmatter
        \chapter*{Na wstępie}\label{chap:one}
        \addcontentsline{toc}{chapter}{\bfseries{Na wstępie}\vspace*{2em}}
        \setcounter{page}{9}

        \section{Section One}
        \lipsum[1-10]
        \section{Section two}
        \lipsum[1]
        \section{Section 3}
        \section{Section 4}
        \lipsum[1-10]
        \section{Section 5}
        \lipsum[1-2]
        \section{Section 6}
        \lipsum[1]
        \section{Section 7}
        \lipsum[1-20]
        \chapter{Second chapter}
        \section{someSection}
        \lipsum[1-20]
        \section{someSection2}
        \lipsum[1-20]
        \chapter{Last chapter}
        \end{document}

答え1

この質問はおそらく質問の中で答えられているでしょうテキストがページの下部(および上部)に揃っていることを確認する

オプションを追加してみてくださいpaper=a4paper,twoside=true,textheight=45\baselineskip+\topskip

geometryドキュメントの-optionsに追加してください。また、パッケージも使用する必要がありますcalc

\usepackage{calc}
\usepackage[paper=a4paper,
            twoside=true,
            bindingoffset=0cm,
            textheight=45\baselineskip+\topskip,
            left=4.65cm, right=4.65cm, top=4cm, bottom=4.25cm
            ]{geometry}

MWE では (実際の文書ではそうかもしれませんが)、 の後にテキストがほとんどなくsection 0.2、その間にテキストのない 2 つのサブセクションがあるため、スペースの問題は解決されません。 はページを分割する適切な場所を見つけられません。実際のテキストを使用するか、の後にLaTeXを使用すると、スペースも消えます。 コマンドを使用することもできます。\lipsum[2-3]section 0.2

\enlargethispage{2\baselineskip}

または

\enlargethispage{-\baselineskip}

問題のあるページにいくつかの行を追加または削除します。

bookこの問題は、 -class がデフォルトとして使用されておりflushbottom、そのためテキストが上下の余白の間で引き伸ばされることから生じます。classraggedbottomオプションにオプションを追加すると、この問題は永久に解消されます。

教訓は: テキストを上下の余白の間に揃えたい場合は、すべての編集が終わったら文書を注意深く確認する必要があります。最後の仕上げで、このタイプのタイプセッティング エラーを修正する微妙な変更を加えることができます。ただし、このような問題をすべて自動的に処理することはできません。

関連情報