Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a series of images that I would like to line up horizontialy, all scaled to a given height, rotated 90 degrees and exactly flush with respect to each other. For example:

\documentclass{article}
\usepackage[draft]{graphicx}

\setlength\parindent{0pt}      % Remove all indents
\pagestyle{empty}              % Empty pagestyle

\newcommand{\tallbox}[1]{%
  \resizebox{!}{6cm}{ %
    \includegraphics[angle=90]{#1}  %
  } %
}

\begin{document}%
\tallbox{gen/2354942681964301350.pdf}%
\tallbox{gen/3719368526636490760.pdf}%
\tallbox{gen/4072051681301936821.pdf}%
\end{document}

This gives:

enter image description here

I cannot figure out how to automatically remove the spacing between the graphics. Any combination of negative \hspace seems to fail when the height is changed. I've tried changing the lengths:

\setlength{\textfloatsep}{0pt}
\setlength{\intextsep}{0pt}
\setlength{\floatsep}{0pt}
\setlength{\itemsep}{0pt}

But none of these seem to change the particular spacing I'm looking for.

share|improve this question
1  
don't use spaces between } % in your definition. –  Herbert Jul 5 '12 at 14:22
    
Note that such transformations can also be easily done with the adjustbox package. –  Martin Scharrer Jul 5 '12 at 14:23
    
@MartinScharrer Tobi/Herbert just solved it (and I'll accept once I can) but could you show an example with adjustbox? I think having that knowledge might be useful for more fine-grained questions. –  Hooked Jul 5 '12 at 14:24
add comment

1 Answer

up vote 4 down vote accepted

There are three superfluous spaces in the definition of \tallbox. Note that the % is the right way to omit additional spaces but if Tex reads …{6cm} % it sees the argument {6cm} followed by a space followed by a comment % since TeX reads strictly form left to right the % in this case only eats the line break (i.e. a space in the output) but not the preceding space. To omit this space to you must type % directly after the last character in a line, as you can see in the example below.

\documentclass{article}
\usepackage[draft]{graphicx}

\setlength\parindent{0pt}      % Remove all indents
\pagestyle{empty}              % Empty pagestyle

\newcommand{\tallbox}[1]{%
  \resizebox{!}{6cm}{% <----------
    \includegraphics[angle=90]{#1}% <----------
  }% <----------
}

\begin{document}%
\tallbox{gen/2354942681964301350.pdf}%
\tallbox{gen/3719368526636490760.pdf}%
\tallbox{gen/4072051681301936821.pdf}%
\end{document}

An other way to omit these spaces is to write the definition in a single line

\newcommand{\tallbox}[1]{\resizebox{!}{6cm}{\includegraphics[angle=90]{#1}}

I prefer and recommend the first way since it’s much more readable and it’s easier to find matching braces. I nearly always use the “more lines solution” except for simple text replacement, like

\newcommand{\TikZ}{Ti\textit{k}Z\xspace}
share|improve this answer
    
Thanks Tobi, I didn't even think that those spaces would count, I thought the % would eat them up. Is it better practice to put a small function like this on one line or use many %? –  Hooked Jul 5 '12 at 14:26
    
@Hooked: See my edit ;-) –  Tobi Jul 5 '12 at 15:12
    
@Hooked: The % "eats" all characters after it, but your spaces were before. In the given solution the % "eats" the end-of-line, which would be otherwise be considered as a space by tex. Note that after a commented-out end-of-line, all spaces are ignored until the first non-space. This allows for indentation of the next line. I think that multiple-line, properly indented code improves readability. You only have to be cautious with those pesky end-of-lines. –  JLDiaz Jul 5 '12 at 15:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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