1

I have been writing a document that has a bunch of geometric figures in it. Each geometric figure is accompanied by some remarks. The remarks always immediately precede (i.e., appear above) the figure they concern. I have used \begin{figure}[H] <remarks, in English> <geometric figure> \end{figure} in order to force each geometric figure always to appear on the same page as my remarks about them, because I prefer that style. If it is important, my figures are written in the tikzpicture environment.

Recently, I decided that the document would look better in a two-column format, so I used multicols. So we've got tikzpicture inside of figure inside of multicol. My question is: How can I make each geometric figure conform to the width of the column it appears in? How does one do that for a particular figure? And how does one do it globally?

In case it matters, my code looks something like this, though for brevity's sake I have included only one of my geometric figures:

\documentclass{article}
\usepackage{tikz}
\usepackage{float}
\usepackage{multicol}
-----------------------
\begin{document}
\begin{multicols}{2}

\begin{figure}[H] Below are two concentric circular arcs, blah blah blah...\

\begin{tikzpicture}[scale=.75, >=Stealth] \draw [gray, very thin] (-4, -4) grid (4, 4); \draw [<->, blue, semithick] (-4.5, 0) -- (4.5, 0); \draw [<->, blue, semithick] (0, -4.5) -- (0, 4.5); \draw [red] (4, 0) arc [start angle=0, end angle=230, radius=4]; \draw [purple] (.5, 0) arc [start angle=0, end angle=315, radius=.5]; \end{tikzpicture} \end{figure}

\end{multicols} \end{document}

Thank you!

Noah J
  • 515
  • Welcome to TeX.SX! This may help: https://tex.stackexchange.com/q/411671/47927 . There is also tikzscale or adjustbox: https://tex.stackexchange.com/q/155314/47927 . – Jasper Habicht Aug 10 '22 at 06:25

1 Answers1

0

A bit rude solution, but it works ...

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{float}
\usepackage{multicol}
\newlength\picwidth

\usepackage{lipsum}

\begin{document} \begin{multicols}{2} \lipsum[1]

\begin{figure}[H] \centering \setlength\picwidth{9cm} % max. width of image \begin{tikzpicture}[scale=\linewidth/\picwidth, % ratio column width/image width >=Stealth] \draw [gray, very thin] (-4, -4) grid (4, 4); \draw [<->, blue, semithick] (-4.5, 0) -- (4.5, 0); \draw [<->, blue, semithick] (0, -4.5) -- (0, 4.5); \draw [red] (4, 0) arc [start angle=0, end angle=230, radius=4]; \draw [purple] (.5, 0) arc [start angle=0, end angle=315, radius=.5]; \end{tikzpicture} \end{figure} \lipsum[2-4] \end{multicols} \end{document}

enter image description here

Zarko
  • 296,517
  • Thanks, that's great! Did you arrive at "9cm" through trial-and-error? I ask because I'm wondering what the best way is to ensure that the images are as wide as possible without exceeding the column width. This is what I tried: (1) Use layout to find the value of textwidth. (2) Subtract columnsep value of the multicols from the textwidth value. (3) Divide the difference by the number of columns. (4) Enter that quotient as the value of picwidth. (5) Replace scale=\linewidth/\picwidth with \resizebox{\picwidth}{!}{<image>}. Is this the most efficient way to do what I describe? – Noah J Aug 10 '22 at 13:57
  • @NoahJustice, well, from image is easy to see that maximal width of image is determined by x-axis. Its lenght is 9cm (from -4.5 cm to +4.5 cm), What is most efficient is in your case matter of preference. However, you shoukd be avare, that using scale box scale also font size in the image, what in proposed solution is not a case. – Zarko Aug 10 '22 at 14:23
  • Ah, that makes sense how you got "9cm," and that's good to note about text resizing. Yet it may not always be so easy to tell the maximal width of an image. Or one may have so many images in the document that, regardless of the difficulty for any individual case, it would be very tedious to set the widths for each image individually. So I wonder whether there is a way to get the maximum width possible for all images globally without dilating the text inside of the images? Thanks again. – Noah J Aug 10 '22 at 14:34
  • @NoahJustice, jes it is a way. You can measure width of image by store it in some savebox and than measure width of box. However, this require that image should be compiled twice. First with natural width for measuring of width and than inserted image in document with calculated scale ratio. When image is simple as shown in question, is manual estimation faster, but at images with more complex structure the measurement of image is way to go. However, when drawing images you may care about their width in advance. You also may consider comments below question and look to given links, – Zarko Aug 10 '22 at 17:45