Margins not properly set in memoir after fixing textblock and ratio margins

I want to print a 24x17 cm book on A4 paper, fixing the textblock size and the ratios between the page margins (as you can see from the comments in the code). Unfortunately, once printed, the textblock size is correct, but the ratios between the margins are not those chosen (there is a bit of inaccuracy): I can not understand what is the problem..

This is the code:

\documentclass[showtrims,12pt,twoside]{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}

\setstocksize{297mm}{210mm} %set the stock size at A4 (297x210mm)
\settrimmedsize{240mm}{170mm}{*} %set the page size at 24x17cm
\settrims{28.5mm}{20mm} %center the page on the stock
\settypeblocksize{185mm}{125mm}{*} %set the textblock size
\setlrmargins{*}{*}{1,5} %set the fore-edge margin 1,5 times the spine margin
\setulmargins{*}{*}{1} %set the lower margin the same as the upper margin

\begin{document}

\chapter{First chapter}
\lipsum[1]
\section{First section}
\lipsum[2-4]
\section{Second section}
\lipsum[5-8]

\end{document}


You're forgetting \checkandfixthelayout:

\documentclass[showtrims,12pt,twoside]{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}

\setstocksize{297mm}{210mm} %set the stock size at A4 (297x210mm)
\settrimmedsize{240mm}{170mm}{*} %set the page size at 24x17cm
\settrims{28.5mm}{20mm} %center the page on the stock
\settypeblocksize{185mm}{125mm}{*} %set the textblock size
\setlrmargins{*}{*}{1.5} %set the fore-edge margin 1.5 times the spine margin
\setulmargins{*}{*}{1} %set the lower margin the same as the upper margin
\checkandfixthelayout

\newcommand{\testmargins}{%
\leavevmode
\makebox[0pt][r]{%
\smash{\vrule width 0.2pt height 30cm depth 30cm}%
\kern-0.2pt
\vrule height 0.1pt depth 0.1pt width 2\dimexpr(170mm-125mm)/5}%
\makebox[0pt][l]{%
\hspace\textwidth
\vrule height 0.1pt depth 0.1pt width 3\dimexpr(170mm-125mm)/5
\kern-0.2pt
\smash{\vrule width 0.2pt height 30cm depth 30cm}%
}%
}

\begin{document}

\chapter{First chapter}
\testmargins
\lipsum[1]
\section{First section}
\lipsum[2-4]
\section{Second section}
\lipsum[5-8]

\end{document}


The \testmargins command just adds some rules to show the margins are exactly as required.

• You're right, I exchanged the measures in \settrims (I've edited the question). Horizontal margins are almost correct (there is 1 mm gap that I do not understand where it comes from), but not so for vertical ones (the test that you created does not highlights). How can I fix? Sep 5 '16 at 13:08
• @tomino I get equal margins on top and bottom, as far as I can see Sep 5 '16 at 13:16
• I don't know why, but for me the top and bottom margins are different, how you can see directly: s18.postimg.org/o4pcoiw7t/bo_1.jpg Sep 5 '16 at 16:56
• No one knows how I can fix it? Sep 6 '16 at 15:07