ITADN

Help for "complex" layouts

#4Closedfrancofusco 创建于 2024-07-26
F
francofuscocommented
Hello! Thanks for the class, it's very nice and intuitive to use! I am experimenting with it to see if I can create some travel pohotobooks where the layouts are a bit more "playful" than what appears in professional photobooks. As an example, my current "challenge" is to create a layout that contains 5 cells as follows (for a "lay-flat" kind of book): ![layout](https://github.com/user-attachments/assets/ce523546-14d6-4e77-aa66-cfdb533a1c99) The "specs" on the sizes are as follows: - The width of all images is the same - The height of all corner images is the same - The (narrow) distance between the images must equal to the gutter (*) - The "corner images" must be at "margin" distance from the page border (not counting the bleed) - The central image must extend to the top and bottom so that it fills the bleed area What I've achieved so far is ok visually, but a bit hacky in the way it is coded. If possible, I need a bit of guidance to clarify some doubts and to improve the solution I came up with. This is what I got. First of all, I created a "backup" of the lengths `\bleed`, `\margin` and `\gutter`, saving them in the lengths `\documentbleed`, `\documentmargin` and `\documentgutter`. I then created a template with `\newtemplate[double, margin=-\documentbleed, gutter=0pt]{complex}{...}`. The reason for `margin=-\documentbleed` is that the "drawing area" should span the whole page, bleed area included. The reason for `gutter=0pt`... is actually not entirely clear to me, I'll get back to it later in the description. With the page setup, I then used `pgfmath` to calculate manually all dimensions and positions needed, then I used `\placeholder{y1 x1 y2 x2}` to allocate the elements. Here is the code for the template: ```.tex \newtemplate[double, margin=-\documentbleed, gutter=0pt]{complex}{ % Dimensions of the drawing area. \pgfmathsetmacro{\drawablewidth}{2 * \pagewidth + 2 * \documentbleed} \pgfmathsetmacro{\drawableheight}{\pageheight + 2 * \documentbleed} % Width and height of the corner pictures. \pgfmathsetmacro{\picwidth}{(\drawablewidth - 2 * \documentbleed - 2 * \documentmargin - 2 * \documentgutter) / 3} \pgfmathsetmacro{\picheight}{(\drawableheight - 2 * \documentbleed - 2 * \documentmargin - \documentgutter) / 2} % Place the first picture in the top-left corner. \pgfmathsetmacro{\rowstart}{(\documentbleed + \documentmargin) / \drawableheight} \pgfmathsetmacro{\rowend}{\rowstart + \picheight / \drawableheight} \pgfmathsetmacro{\colstart}{(\documentbleed + \documentmargin) / \drawablewidth} \pgfmathsetmacro{\colend}{\colstart + \picwidth / \drawablewidth} \placeholder{{\rowstart} {\colstart} {\rowend} {\colend}} % Place the second picture in the bottom-left corner. \pgfmathsetmacro{\rowstart}{(\documentbleed + \documentmargin + \picheight + \documentgutter) / \drawableheight} \pgfmathsetmacro{\rowend}{\rowstart + \picheight / \drawableheight} \pgfmathsetmacro{\colstart}{(\documentbleed + \documentmargin) / \drawablewidth} \pgfmathsetmacro{\colend}{\colstart + \picwidth / \drawablewidth} \placeholder{{\rowstart} {\colstart} {\rowend} {\colend}} % Place the third picture in the middle. \pgfmathsetmacro{\colstart}{(\documentbleed + \documentmargin + \picwidth + \documentgutter) / \drawablewidth} \pgfmathsetmacro{\colend}{\colstart + \picwidth / \drawablewidth} \placeholder{0 {\colstart} 1 {\colend}} % Place the fourth picture in the top-right corner. \pgfmathsetmacro{\rowstart}{(\documentbleed + \documentmargin) / \drawableheight} \pgfmathsetmacro{\rowend}{\rowstart + \picheight / \drawableheight} \pgfmathsetmacro{\colstart}{(\documentbleed + \documentmargin + 2 * \documentgutter + 2 * \picwidth) / \drawablewidth} \pgfmathsetmacro{\colend}{\colstart + \picwidth / \drawablewidth} \placeholder{{\rowstart} {\colstart} {\rowend} {\colend}} % Place the fifth picture in the bottom-right corner. \pgfmathsetmacro{\rowstart}{(\documentbleed + \documentmargin + \picheight + \documentgutter) / \drawableheight} \pgfmathsetmacro{\rowend}{\rowstart + \picheight / \drawableheight} \pgfmathsetmacro{\colstart}{(\documentbleed + \documentmargin + 2 * \documentgutter + 2 * \picwidth) / \drawablewidth} \pgfmathsetmacro{\colend}{\colstart + \picwidth / \drawablewidth} \placeholder{{\rowstart} {\colstart} {\rowend} {\colend}} } ``` The code above works, but it has a limitation: to change the margin and distance between pictures, it is necessary to do manually change the "back-up lengths" as in: ```.tex \begingroup \setlength{\documentmargin}{5mm} \setlength{\documentgutter}{5mm} \template{complex}{ \graphic{img1} \graphic{img2} \graphic{img3} \graphic{img4} \graphic{img5} } \endgroup ``` which is breaking the (clear and simple) API used in `\template[]{}` - where you would simply set the values using the keyword arguments. I've tried a different approach that does not need to use `documentmargin` & friends, but it appears to be broken. More precisely, I create a page without changing the margin, and then position everything relative to the drawing area - which is the page, minus the bleed and the margin. The corner images are placed with ease, but when I try to position the center image something goes wrong. The code I need to execute is: ```.tex % Start in a negative row - since we need to reach the top margin of the page. \pgfmathsetmacro{\rowstart}{-(\margin + \bleed) / \drawableheight} % End at the bottom of the page. Since \rowstart is negative, \rowend is larger than 1. \pgfmathsetmacro{\rowend}{1 - \rowstart} % THIS DOES NOT WORK % The starting and ending columns are calculated relative to the drawing area similarly to what is done in the working version of the template. \pgfmathsetmacro{\colstart}{(\picwidth+\gutter) / \drawablewidth} % Place the object. \placeholder{{\rowstart} {\colstart} {\rowend} {\colend}} ``` The code above produces the following spread: ![broken-layout](https://github.com/user-attachments/assets/f41a184a-22cc-4bb4-90e4-8b92e5b3f1a2) A simplified version of the failing code (which places only the center image using a hard-coded width) is the following: ```.tex \newtemplate[double]{broken}{ \pgfmathsetmacro{\drawablewidth}{2 * \pagewidth - 2 * \bleed - 2 * \margin} \pgfmathsetmacro{\drawableheight}{\pageheight - 2 * \bleed - 2 * \margin} \pgfmathsetmacro{\rowstart}{-(\margin + \bleed) / \drawableheight} \pgfmathsetmacro{\rowend}{1 - \rowstart} % THIS DOES NOT WORK \placeholder{{\rowstart} 0.25 {\rowend} 0.75} } ``` Note that if I set `\rowend` manually to 1, then the image is placed as expected (despite the negative initial row): ![semibroken-layout](https://github.com/user-attachments/assets/b885b6db-ac54-40b2-b74d-c6ce4359d8cf) Any idea how to fix this? I also have a couple of random doubts: - Is it correct that the gutter in this package refers to the distance between pictures? In other contexts, I've seen it used to refer to the inner margin of a page, where the pages are bound together. - Is the gutter applied around images when calling `\placeholder`? Because when prototyping the template I tried keeping the gutter as it was, and simply use `\gutter` for spacing images. However, the result was that images were twice as far as I would expect. My conclusion was that the gutter is "applied" around each image and thus I "deactivated" it using `gutter=0pt` in the template declaration, and resorted to the use of `\documentgutter` for all calculations. - What would be a simple way to create "parametric templates"? As an example, say that I wanted the width of the middle picture to be a (user-supplied) fraction of the width of the other pictures. How would you suggest to define "extra parameters" that need to be used inside a template? Thanks in advance for any help that can be given!
关闭于 2025-03-05 2 条评论