In Automatic scaling of tikz images in floatrow I was asking how to scale several images in one row to the same height and to scale the resulting row to linewidth.

I would like to automate the process further and was wondering if it is possible to define an environment as follows (the desired behaviour will be explained below):


The environment should collect all the code inside \scaledImage, so I can use the method given in the answer to the referenced question automatically to calculate the scaleratios for each image.

After running this calculations, I would like to replace \scaledImage{code} with code and every occurence of \scalefactor inside code with the scalefactor I calculated and actually render the code in the environment.

The reason why I want to render the image twice is that I aim to use tikzscale, otherwise I could replace code by the savebox I will need to calculate the width.

Note: I would like to at least try some of the required coding myself to get started with latex coding, however I am a complete novice, while I am sure that most of this is feasible, I am not sure about the extraction of the scaledImage part from the enviornment. I would appreciate a good pointer on that so I can try what I can put together from that point.

What makes the matter slightly more difficult is that I am afraid of side effects. So I think just executing all code twice (once hidden e.g. by putting it in an sbox or somehow throwing its output away) is dangerous, if for instance a counter is modified.


Your specifications are somewhat vague, so I may have taken some liberties in interpreting what you wanted to do.

For those who are not familiar with your earlier question, I should point out here that you requested and I introduced the concept of a "row-figure" which is constructed of various sized subfigures, all of which are to be scaled (with aspect ratio preserved) in such a way as to occupy an overall width specified by the user (default \textwidth).

I have introduced the following commands that work inside an environment:

\rowfigurewidth{specified width of row-figure} - which defaults to \textwidth

\startrowfigure[starting subfig number]{left-most image to store in the new row-figure}

\addrowfigure{figure to store at current right-end of row-figure}

\presentrowfigure - regurgitates the currently constructed row figure

\showrowfigure{}{}{}{} - the macro that formats each subfigure component of the row-figure (not called by user, but determines format of presented row-figure)

rowfigcount is the counter that contains the current value of subfigs employed, if one wishes continue on a subsequent line (via \therowfigcount as optional argument to \startrowfigure.

Sample usage would be:


And the whole code is given below:

  \expandafter\def\csname rowfig\roman{rowfigcount}\endcsname{#2}%
  \expandafter\def\csname rowfig\roman{rowfigcount}\endcsname{#1}%
  \whiledo{\value{rowfigindex} < \value{rowfigcount}}{%
      {\csname rowfig\roman{rowfigindex}\endcsname}%
      {\csname rowfig\roman{rowfigcount}\endcsname}%


Here I demonstrate row figures:

\caption{These are my row figures}

which came from these raw images:

\caption{These are the unaltered images}

enter image description here

Obviously, if you wanted to do something more than just put a (subfig number) below the individual images, you would have to pass it to \startrowfig and \addrowfig, store it, and recall it via an entry in \showrowfigure

  • +1 for a nice almost solution. The idea of the question was that I could use floatrow to place the images (thus maintaining its labeling and captioning capabilities as well as its framing) and be able to actually use tikzscale to scale the images. Apparently there is no (easy) way to do so. If I adopt your solution I first have to start/addrowigure and then (width some modifications) I could create my floatrow code and insert e.g. tikzscale{scale=\rowFigScale}{figure}. (I would combine the two scalefactors, so I can apply them in one scale avoiding the quality loss from double scaling)
    – ted
    Jul 31 '13 at 15:52
  • I was hoping I could prevent this and write code that can be inserted in the right spaces from the beginning (directly in the floatrow code.)
    – ted
    Jul 31 '13 at 15:53
  • @ted. Got it. I'll give it some more thought, though I'd have to learn how floatrow works. In the meantime, perhaps the contents of \showrowfigure could somehow be passed to floatrow in some fashion, once the \startrowfigure and \addrowfigure are accomplished. Jul 31 '13 at 15:59
  • I would like to chat about this with you, but I am not aware how the chat feature works...
    – ted
    Jul 31 '13 at 16:03
  • 1
    I was about to add a floatrow example but I think it does not quite belong in the question, therefor take a look at the mwe in this question. Also I am trying to write a package now, no doubt you will get credit what so ever, the question is if you would like to collaborate on it, if so we have to find a place where I can show you what I have come up width based on your awnser and my other quesitons.
    – ted
    Aug 1 '13 at 16:47

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.