将图片底部与章节标题对齐

将图片底部与章节标题对齐

请考虑以下示例,其中章节编号非常大并放在蓝色框中:

\documentclass[svgnames]{scrbook}

\usepackage{titlesec}
\usepackage{tocloft}
\usepackage{tikz}


\usepackage{lipsum}% http://ctan.org/pkg/lipsum


\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=5em, text centered, rounded corners, minimum height=4em]
\renewcommand*{\chapterformat}{%
\begin{tikzpicture}[node distance = 2cm, auto]%
    \node [block] (init) {\fontsize{80}{88}\selectfont\thechapter};%
\end{tikzpicture}\enskip}


\begin{document}

\chapter{Short Title}

\section{Rectangular coordinates} \lipsum[1]
\section{Projections of a segment on the axes} \lipsum[2]
\section{Distance between two points} \lipsum[3]
\section{The mid-point of a segment} \lipsum[4]
\section{Division of a segment in any ratio} \lipsum[5]
\section{Oblique coordinates} \lipsum[6]

\chapter{Title Which is Really Just Way Too Long}

\section{First illustrations} \lipsum[1]
\section{Curve plotting} \lipsum[2]
\section{Test that a point lie on a curve} \lipsum[3]
\section{Intercepts} \lipsum[4]
\section{Points of intersection of two curves} \lipsum[5]
\section{Oblique coordinates} \lipsum[6]

\end{document}

第一章没问题:矩形的基线与标题的基线对齐。然而,第二章的情况并非如此。有没有办法解决这个问题,让蓝色框的基线与章节标题的基线对齐,而不管长度如何?

这很棘手,因为在文档正文中,有几种可能的解决方案。但在格式化章节标题时,所有方法显然都行不通。

当然,如果你能想到更好的方法来制作这个大蓝盒子,我会很高兴听到它!:)

答案1

我将使用titlesec及其explicit选项来设计章节标题;两个minipage底部对齐的 s 将负责数字和标题的对齐;类似于这些(请根据需要随意调整长度):

\documentclass[svgnames]{scrbook}
\usepackage{fix-cm}
\usepackage[explicit]{titlesec}
\usepackage{tikz}
\usepackage{lipsum}

\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=5em, text centered, rounded corners, minimum height=4em]

% the width of the box containing the chapter number
\newlength\mylen
\setlength\mylen{150pt}

\titleformat{\chapter}[display]
  {\normalfont\huge\bfseries}{}{20pt}
  {\begin{minipage}[b]{\mylen}
      \begin{tikzpicture}[node distance = 2cm, auto]%
        \node [block] (init) {\fontsize{80}{88}\selectfont\sffamily\thechapter};%
      \end{tikzpicture}
    \end{minipage}%
    \begin{minipage}[b]{\dimexpr\linewidth-\mylen\relax}
       \raggedright\sffamily #1
    \end{minipage}
}
\titlespacing*{\chapter}{0pt}{-50pt}{20pt}

\begin{document}

\chapter{Short Title}

\section{Rectangular coordinates} \lipsum[1]
\section{Projections of a segment on the axes} \lipsum[2]
\section{Distance between two points} \lipsum[3]
\section{The mid-point of a segment} \lipsum[4]
\section{Division of a segment in any ratio} \lipsum[5]
\section{Oblique coordinates} \lipsum[6]

\chapter{Title Which is Really Just Way Too Long}

\section{First illustrations} \lipsum[1]
\section{Curve plotting} \lipsum[2]
\section{Test that a point lie on a curve} \lipsum[3]
\section{Intercepts} \lipsum[4]
\section{Points of intersection of two curves} \lipsum[5]
\section{Oblique coordinates} \lipsum[6]

\end{document}

在此处输入图片描述

答案2

你可以使用

\chapter[Title Which is Really Just Way Too Long]%
  {\parbox[b]{0.6\linewidth}{Title Which is Really Just Way Too Long}}

将章节标题放在底部对齐的段落框中b。我还添加了一个未放在 内的目录条目\parbox,因为目录可能会正确处理对齐。选择0.6\linewidth足以确保 的内容\parbox不会溢出右边距。

在此处输入图片描述

相关内容