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.

Background

Trying to place an image within two-column text.

Problem

The image renders as follows, where the vertical bar is the column separator:

Undefined Image

Code

The following code produces the problem image:

  \placefigure[]{}{%
    \externalfigure[7bee7b104cc5c6.jpg][
      width=\textwidth,
    ]
  }

The following code, however, successfully embeds the image:

  \placefigure[]{}{%
    \externalfigure[7bee7b104cc5c6.jpg][
      width=100px,
    ]
  }

The problem is that the width of 100px does not cause the image to expand to the local width (i.e., the width of the current column).

Ideas

Some things I have tried:

width=\textwidth,
width=\the\textwidth,
width=\linewidth,
width={\the\textwidth},
width=local,

And even this:

\newdimen\imgwidth
\imgwidth=200px
...
width={\the\imgwidth},

Question

How do you place a figure within a column such that it scales to fit the width?

Minimum Working Example

Here is a small code snippet that illustrates the problem:

% interface=en output=pdftex

\definemixedcolumns[StyleColumns][
  n=2, 
  separator=rule,
  align=tolerant,
  before={\blank[big]},
]

\setupexternalfigures[
  order={svg,pdf,png,jpg},
  location=global,
  %wfactor=fit,
]

\setuphead[section][
  after={\startStyleColumns},
  aftersection={\stopStyleColumns},
]

\starttext

\startbodymatter
  \setuppagenumbering[conversion=numbers]
  \setcounter[userpage][1]

  \startchapter[
    title={Chapter},
    reference=sec:chapter,
  ]

  \startsection[
    title={Section},
    reference=sec:chapter,
  ]

  \placefigure[]{}{%
    \externalfigure[sheep.jpg][
        width=\textwidth,
      ]
  }

  \startsubsection[
    title={Equipment},
    reference=sec:equipment,]
    \input knuth
  \stopsubsection

  \stopsection
  \stopchapter
\stopbodymatter

\stoptext

Comment out the width=\textwidth, line to see the image appear.

share|improve this question
    
Can you crate a minimal example to show that width=\linewidth or width=\hsize does not work. –  Aditya Sep 1 '13 at 23:25
    
@Aditya: \hsize works; \linewidth makes the image disappear altogether. Is wfactor less efficient than width? –  Dave Jarvis Sep 1 '13 at 23:48
2  
Hmm...it seems that there is a bug with \textwidth and \linewidth inside mixed columns. Please report it to the context mailing list. Using wfactor is OK. I'd rather use \defineexternalfigure[fullwidth][factor=fit] and then use \externalfigure[file.jpg][fullwidth], as it makes it easy to change the style if the style changes in the future. See ConTeXt wiki for details. –  Aditya Sep 1 '13 at 23:55
add comment

1 Answer

up vote 1 down vote accepted

Use the following:

\placefigure[]{}{%
  \externalfigure[7b104cc5c6.jpg][wfactor=fit]
}

The documentation for \externalfigure refers to the \useexternalfigure command. The externalfigure command appears to inherit all the behaviours of the useexternalfigure command, including wfactor. Use wfactor to control the stretch of the width, independently from the stretch of the height.

To ensure that all figures throughout the document use the same fit, you can define the fit requirement once:

\setupexternalfigures[
  order={svg,pdf,png,jpg},
  location=global,
  wfactor=fit,
]

The location=global indicates that the images can come from anywhere in the file system.

share|improve this answer
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.