将章节号放在奇数页的方框中

将章节号放在奇数页的方框中

我正尝试将章节编号放在奇数页的框中。每个偶数页上都有章节编号的方框很有帮助。但我正试图将方框移到奇数页。我尝试了几种方法,但都没有成功。

\documentclass[11pt,a4paper,openright,twoside]{report}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage{amsmath}
%\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage[document]{ragged2e}
\usepackage{pdfpages}

\usepackage[paperheight=24cm,paperwidth=17cm,left=2.5cm,right=2cm,top=2cm,bottom=2cm, footskip=1cm]{geometry}
\usepackage{blindtext}
\usepackage{lipsum}
\usepackage{indentfirst}
\setlength\parindent{1cm}

\usepackage{CormorantGaramond}
\usepackage[T1]{fontenc}

% Adding box to the chapter
\usepackage{rotating}
\usepackage{eso-pic,xcolor}
\definecolor{chapterthumbbg}{HTML}{6F7170}
%\AddToShipoutPictureFG{%
%  \AtPageLowerLeft{%
%    \ifshowchapterthumb\ifodd\value{page}
%      \makebox[\paperwidth][r]{%
%        \raisebox{\dimexpr.5\paperheight-.5\height}{%
%          \setlength{\fboxsep}{\baselineskip}%
%          \colorbox{chapterthumbbg}{\textcolor{white}{\begin{turn}{0}\textbf{{\LARGE \thechapter}}\end{turn}}}%
%        }%
%      }%
%    \fi\fi
%  }
%}
\AddToShipoutPictureFG{%
  \AtPageLowerLeft{%
    \ifshowchapterthumb%\ifodd\value{page} % <==========================
      \makebox[\paperwidth][r]{%
        \raisebox{\dimexpr.5\paperheight-.5\height}{%
          \setlength{\fboxsep}{\baselineskip}%
          \colorbox{chapterthumbbg}{\textcolor{white}{\thechapter}}%
        }%
      }%
    \fi%\fi % <=========================================================
  }
}

\newif\ifshowchapterthumb

\renewcommand{\baselinestretch}{1.1}
\newcommand*\chem[1]{\ensuremath{\mathrm{#1}}}
\renewcommand{\theequation}{Eq. \arabic{equation}}



%\usepackage{titlesec}

%\titleformat{\chapter}[hang]{\huge\bfseries}{}{0pt}{}

%\titleclass{\chapter}{page}
%\assignpagestyle{\chapter}{empty}
%\titleformat{\chapter}
%    [display]
%    {\centering\Huge\bfseries}
%    { }
%    {0pt}
%    {\huge}
%    [\clearpage]



\begin{document}


%\showchapterthumbfalse
%
%\input{Frontmatter/Title}
%\pagebreak
%\input{Frontmatter/committe}
%\pagebreak
%\input{Frontmatter/official_title}
%\pagebreak
%\input{Frontmatter/approvedby}


\tableofcontents
%\newpage
%\thispagestyle{empty}
%\mbox{}

\part{Name 1}
\showchapterthumbtrue
\chapter{First chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\chapter{Second chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]
\showchapterthumbfalse

\part{Name 2}
\showchapterthumbtrue
\chapter{Third chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\chapter{Last chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]
\showchapterthumbfalse

%\include{Mainmatter/Chapter_1}
%%\newpage
%%\thispagestyle{empty}
%%\mbox{}
%\include{Mainmatter/Chapter_2}
%%\newpage
%%\thispagestyle{empty}
%%\mbox{}
%
%\part{Name}
%\include{Mainmatter/Chapter_3}



\end{document}

此代码只适用于偶数页。我想将框移到奇数页。如能提供一些意见,我们将不胜感激。提前致谢。

答案1

使用构造

\ifodd\value{page} % is value of page odd then do
  % code to be executed for odd page
\else
  % code to be executed for even pages
\fi

你可以定义要做什么。我理解你的问题,你想要盒子仅有的在奇数页上。因此你需要的代码如下:

\ifodd\value{page}
      \makebox[\paperwidth][r]{%
        \raisebox{\dimexpr.5\paperheight-.5\height}{%
          \setlength{\fboxsep}{\baselineskip}%
          \colorbox{chapterthumbbg}{\textcolor{white}{\thechapter}}%
        }%
      }%
\fi

使用以下 MWE

\documentclass{report}

\usepackage{lipsum}
\usepackage{eso-pic,xcolor}

\definecolor{chapterthumbbg}{HTML}{6F7175}

\AddToShipoutPictureFG{%
  \AtPageLowerLeft{%
    \ifshowchapterthumb\ifodd\value{page} % <=================================
      \makebox[\paperwidth][r]{%
        \raisebox{\dimexpr.5\paperheight-.5\height}{%
          \setlength{\fboxsep}{\baselineskip}%
          \colorbox{chapterthumbbg}{\textcolor{white}{\thechapter}}%
        }%
      }%
    \fi\fi
  }
}

\newif\ifshowchapterthumb

\sloppy% Just for this document

\begin{document}

\showchapterthumbfalse% Default

\tableofcontents

\clearpage

\showchapterthumbtrue% Show chapter thumbs

\chapter{First chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\chapter{Second chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\chapter{Third chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\chapter{Last chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\end{document}

你只会在奇数页上看到章节的方框,例如:

如果您想要在偶数页和奇数页上使用框,只需使用(只需删除包含\ifodd和 的行\fi):

  \makebox[\paperwidth][r]{%
    \raisebox{\dimexpr.5\paperheight-.5\height}{%
      \setlength{\fboxsep}{\baselineskip}%
      \colorbox{chapterthumbbg}{\textcolor{white}{\thechapter}}%
    }%
  }%

由此得出的 MWE

\documentclass{report}

\usepackage{lipsum}
\usepackage{eso-pic,xcolor}

\definecolor{chapterthumbbg}{HTML}{6F7175}

\AddToShipoutPictureFG{%
  \AtPageLowerLeft{%
    \ifshowchapterthumb%\ifodd\value{page} % <==========================
      \makebox[\paperwidth][r]{%
        \raisebox{\dimexpr.5\paperheight-.5\height}{%
          \setlength{\fboxsep}{\baselineskip}%
          \colorbox{chapterthumbbg}{\textcolor{white}{\thechapter}}%
        }%
      }%
    \fi%\fi % <=========================================================
  }
}

\newif\ifshowchapterthumb

\sloppy% Just for this document

\begin{document}

\showchapterthumbfalse% Default

\tableofcontents

\clearpage

\showchapterthumbtrue% Show chapter thumbs

\chapter{First chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\chapter{Second chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\chapter{Third chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\chapter{Last chapter}\lipsum[1-5]
\section{First section}\lipsum[6-10]
\section{Second section}\lipsum[11-15]
\section{Third section}\lipsum[16-20]
\section{Last section}\lipsum[21-25]

\end{document}

你可以得到带有方框的偶数页和奇数页:

在此处输入图片描述

产生奇数页

相关内容