1

I am using the memoir class to write a document. I have a rather long title that only fits in two lines, and the justification of the chapter title is not to my liking. This is my current setup (MWE):

\documentclass[a4paper]{memoir}
\usepackage{calc,lipsum}



\makechapterstyle{myChapStyle}{
\chapterstyle{komalike}
\setlength{\beforechapskip}{40pt}
\setlength{\chapindent}{\marginparsep}
\renewcommand*{\printchapternum}{%
    \framebox[\chapindent][r]{\chapnumfont \quad\thechapter}}
}
\chapterstyle{myChapStyle}



\begin{document}
  \chapter{Fundamentals of medical imaging and continuum mechanics}
  \lipsum[1-3]
\end{document}

I would like to have the following:

  1. The chapter number is left justified with the paragraphs (that follow)
  2. The space between the chapter number and the chapter title is consistent (when no boxes/frames are used).
  3. The second line of the chapter title is left-justified with the first line of the title. In this case, 'mechanics' should be aligned with 'Fundamentals'.

I already had a look at this post but this did not work. I used this second, and more concise solution:

\renewcommand*{\printchapternum}{%
   \@hangfrom{\chapnumfont \thechapter\quad}}%

The MWE adapted to the proposed (by Daleif) solution (which doesn't compile):

\documentclass[a4paper]{memoir}
\usepackage{calc,lipsum}
\makechapterstyle{myChapStyle}{
    \chapterstyle{komalike}
    \setlength{\beforechapskip}{40pt}
    \renewcommand{\printchaptername}{}
    \renewcommand{\chapternamenum}{}
    \renewcommand{\printchapternum}{}%\chapnumfont \thechapter\space}
    \renewcommand{\afterchapternum}{}
    \renewcommand*{\printchapternum}{%
        \@hangfrom{\chapnumfont \thechapter\quad}}%
}
\chapterstyle{myChapStyle}

\begin{document}
    \chapter{Fundamentals of medical imaging and continuum mechanics}
    \lipsum[1-3]
\end{document}

The example was probably working on an older version of Memoir. Compilation fails with the following error messages:

  • You can't use `\spacefactor' in vertical mode. ...f medical imaging and continuum mechanics}
  • Missing $ inserted. ...f medical imaging and continuum mechanics}
  • and some other errors associated with using fonts.

I'm using \framebox rather than \makebox just to visualize the positioning of the chapter title and chapter number.

I hope I have given you enough information to help me out.

UPDATE: Daleif's suggestion to use the \makeatletter and \makeatother was missing in my code. Adding that solved my problem.

Thanks,

Ellankavi

  • Did you read the example in the link post very carefully? The example with \@hangfrom is surrounded by a \makeatletter...\makeatother pair. Did you remember to copy that? Remember in user space @ is not allowed in macro names, unless you it it is ok. – daleif Mar 22 '18 at 11:21
  • I'm sorry that I missed that! It works. What is the best way to go ahead? Accept your answer, delete this post (can I?), or change the OP? THANKS! – kane Mar 22 '18 at 11:31
  • If it is just a normal user error, then just delete the question, it will probably not help others (I don't really care about the points) – daleif Mar 22 '18 at 12:21
0

(1) Welcome, (2) here is a suggesting (I'd lkke to know which parts of the old post did not work? Justed retested the code from the mentioned post, it works just fine)

\documentclass[a4paper]{memoir}
\usepackage{kantlipsum}

\makechapterstyle{myChapStyle}{
  \chapterstyle{komalike}
  \setlength{\beforechapskip}{40pt}
  \setlength{\chapindent}{\marginparsep}
  \renewcommand\printchapternum{}
  \renewcommand\printchaptertitle[1]{%
    \begin{tabularx}{1.0\linewidth}{
      @{} % no space on the left of the table
      l % left aligned for the number
      @{\quad} % space between the columns
      >{\raggedright\arraybackslash} %ragged right column
      X % width auto adjusting column
      }
    \chapnumfont \thechapter & \chaptitlefont ##1
  \end{tabularx}
}
}
\chapterstyle{myChapStyle}


\begin{document}
  \chapter{Fundamentals of medical imaging and continuum mechanics}
  \kant
\end{document}
  • Hello Daleif, Thanks for that post of yours. I went with the second and more concise version that had these lines (sorry if the code does not appear in the code block; it's my first time posting here.): \renewcommand*{\printchapternum}{% \@hangfrom{\chapnumfont \thechapter\quad}}% – kane Mar 22 '18 at 11:05
  • @kane please dont post code in comments, update your question. Is there a line break after that %? – daleif Mar 22 '18 at 11:07
  • I'm sorry. Your current suggestion (with tabularx) works but I'm curious if your other suggestion in your earlier post (linked in OP) also works. Does it work if you include those lines in my MWE? – kane Mar 22 '18 at 11:11
  • Which lines? Again, please update your example, just add another example to it. Remember we are not being paied to be here.... – daleif Mar 22 '18 at 11:15
  • I'll accept your answer, which also works. – kane Mar 22 '18 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.