1

I'm new to LaTex and I'm setting a book I wrote some time ago; a collection of tunes, each with a short paragraph or two of text. I've scanned the music, rather than typesetting it in MusixTex, because I originally hand-wrote it, and I like the look of it as it is.

I'm setting in A4:

\documentclass[a4paper,12pt,twoside,openany]{book}

The width of the staves should be 18.7cm, or 530pt. I am happy to leave the text at its default margins, and I certainly don't want to make it as wide as the music. Unfortunately, the images are not always exactly the same width as each other, because the scans were trimmed and there is a varying amount of matter to the left and right of the staves. This means I need to adjust the width and position of each image individually to make sure the staves are of consistent width, and positioned correctly.

What I'm trying to do is to insert each image between its chapter heading and the text in such a way that it is consistently placed and sized, taking into account left and right pages.

What I need, effectively, is a pair of guides for the images which are independent of the text margins. I was hoping I could use a box with a visible border, fixed at 530pt width, put the image inside that, move and resize the image appropriately within the box, then turn off the visible border when I'm happy. Or, just add a pair of vertical rules 530pt apart, positioned to take into account odd and even pages. But I haven't managed to work out how to do either of those things.

Inserting, placing and resizing the images are all fine, I just can't work out how to know exactly where to put them!

Thanks

1

Perhaps you are looking for something like this? First I show two 530pt images "centered" by LaTeX, the 2nd image with some croppable space around it. This produces images not only misaligned, but because the image width exceeds the margins, they are also not actually centered, either.

I instead, introduce \shiftimg that takes a horizontal shift and an uncropped image as its two arguments, which allows the two arbitrarily cropped images to be lined up. Furthermore, by incorporating a \pageshift that flip-flops positive and negative on succeeding pages, it will keep the page margins the same on even and odd pages, with the same invocation arguments. This is very useful, if repagination repositions an image to an adjacent page.

Lastly, I put in commentable code that lays out vertical rules spaced 530pt apart on the paper, symmetric to the paper edge. This allows you to fine-tune the adjustment.

\documentclass[a4paper,12pt,twoside,openany]{book}
\usepackage{everypage}
\def\pageshift{42pt}
\AddEverypageHook{\xdef\pageshift{\the\dimexpr-\dimexpr\pageshift\relax\relax}}
%\usepackage[showframe,pass]{geometry}
\usepackage{graphicx,lipsum}
\def\imgA{\includegraphics[width=530pt,height=2cm]{example-image}}
\def\imgB{~~~~\includegraphics[width=530pt,height=2cm]{example-image}\,}
\newcommand\shiftimg[2]{\makebox[\dimexpr\textwidth+#1+\pageshift\relax][c]{#2}}
%%%%% CAN BE COMMENTED FOR FINAL VERSION
% THESE ARE LaTeX DEFAULTS; CAN CHANGE IF NEEDED.
\def\PageTopMargin{1in}
\def\PageLeftMargin{1in}
\newcommand\atxy[3]{%
 \AddEverypageHook{\smash{\hspace*{\dimexpr-\PageLeftMargin-\hoffset+#1\relax}%
  \raisebox{\dimexpr\PageTopMargin+\voffset-#2\relax}{#3}}}}
\def\imgoffset{\the\dimexpr.5\dimexpr\paperwidth-530pt\relax\relax}
\atxy{\imgoffset}{0pt}{\rule[-\paperheight]{.1pt}{\paperheight}}
\atxy{\dimexpr\paperwidth-\imgoffset\relax}{0pt}{\rule[-\paperheight]{.1pt}{\paperheight}}
%%%%%
\begin{document}
Unaltered uncropped images:\par
{\centering
\imgA\par\imgB\par}
\lipsum[1]
\shiftimg{-33pt}{\imgA}\par\shiftimg{-47pt}{\imgB}\par
\lipsum[3-6]
\shiftimg{-33pt}{\imgA}\par\shiftimg{-47pt}{\imgB}\par
\end{document}

enter image description here

enter image description here

  • This really does look like it's going to help a lot, thank you very much. It's not immediately evident to me what's going on, but I'm learning just from looking at your code and that and can only be a good thing! – Spunto the Rat Boy Jan 15 '17 at 13:23
  • I am having one problem with this solution. Currently, each chapter has a chapter heading, an image, and some text, thus: \chapter{Tune number two}% \shiftimg{-3pt}{\includegraphics[width=540pt]{tune-02-img}} What a lovely tune this is. As I increase the size of the images past a certain point, a blank page is inserted before the chapter heading. Is there any obvious way round that? – Spunto the Rat Boy Jan 15 '17 at 16:20
  • @SpuntotheRatBoy By "increase the size of the images past a certain point", I presume the issue is vertical height of image, since \shiftimg should take care of horizontal overruns. If something runs off the bottom margin in one fell swoop, like an oversize image, the blank page often results. The solution is to make sure the image is not so tall vertically as to run off the bottom text-area margin. If you uncomment the \usepackage[showframe,pass]{geometry} line in my preamble, the text area of the page is outlined, so you can see if your image exceeds it. – Steven B. Segletes Jan 15 '17 at 17:43
  • @SpuntotheRatBoy Alternately, you can change the page margins to accommodate. – Steven B. Segletes Jan 15 '17 at 17:43
  • Thanks @Steven — vertical height makes sense as the culprit, although I'm only setting the horizontal height explicitly. I can't change the aspect ratio of the images, so it looks like messing with the top and bottom margins is the way forward. Thank you so much for your help! – Spunto the Rat Boy Jan 15 '17 at 20:17

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.