Graphics, Figures & TablesShrink text in a picture

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Singularity
Posts: 156
Joined: Sat Jan 22, 2011 9:55 pm

Shrink text in a picture

Post by Singularity »

Hello. I'm new to LaTex. I tried to make a picture of a one-dimensional spring and mass system (i.e., several masses in a line connected by springs)) to put atop my thesis. Here's what I came up with:

Code: Select all

\begin{picture}(0,0)
	% A (left) spring and mass. 
	\newsavebox{\SandM}
	\savebox{\SandM}(28,10)[bl]{
		\put(0,5){\line(1,0){8}}
		\put(8,5){\circle{3}}
		\put(10,5){\circle{3}}
		\put(12,5){\circle{3}}
		\put(12,5){\line(1,0){8}}
		\put(20,2){\line(0,1){6}}
		\put(20,2){\line(1,0){8}}
		\put(20,8){\line(1,0){8}}
		\put(28,2){\line(0,1){6}}
	}
	
	% Left wall.
	\put(0,0){\line(0,1){10}}
	
	% First two masses.
	\multiput( 0,0)(28,0){2}{\usebox{\SandM}}
	\put(56,5){\line(1,0){8}}
	
	% Elipses (well, sorta).
	\put(67,5){\circle{0}}
	\put(69,5){\circle{0}}
	\put(71,5){\circle{0}}

	% Last two masses.
	\multiput(74,0)(28,0){2}{\usebox{\SandM}}
	\put(130,5){\line(1,0){8}}
	
	% Right wall.
	\put(138,0){\line(0,1){10}}
	
	% Springs' and mass' labels.
	\put(6,15){$s_0$}
	\put(17,15){$m_0$}
	
	\put(33,15){$s_1$}
	\put(45,15){$m_1$}

	\put(105,15){$s_n$}
	\put(117,15){$m_n$}

\end{picture}
It's OK, but I'd like to shrink the text and put the mass' labels inside the boxes. Also, a more professional looking ellipsis would be nice (but a secondary goal). I also appreciate any other suggestions.

Thanks.
Last edited by Singularity on Thu Feb 24, 2011 2:42 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

Frits
Posts: 169
Joined: Wed Feb 02, 2011 6:02 pm

Shrink text in a picture

Post by Frits »

Personally, I don't like to 'code my images'. The way I make my images is described here.

If that doesn't satisfy you, TikZ probably does.
howtoTeX.com - Your LaTeX resource site (Tips, Tricks, Templates and more!)
Follow howtoTeX on twitter
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Shrink text in a picture

Post by localghost »

Rely on packages like pgf/tikZ or PSTricks for such sketches. Instead of scaling down the text you better scale up the graphical elements.


Thorsten
Singularity
Posts: 156
Joined: Sat Jan 22, 2011 9:55 pm

Shrink text in a picture

Post by Singularity »

localghost wrote:Rely on packages like pgf/tikZ or PSTricks for such sketches. Instead of scaling down the text you better scale up the graphical elements.
From the descriptions at Wikibooks, it looked like pgf/tikZ would serve my purposes. I read a tutorial on it. Thanks for the info.
localghost wrote:As soon as the problem is sorted out, please act exactly according to Section 3 of the Board Rules (can be found on top of each forum in the »Announcements« section).
Well, there isn't really a 'solution', per se, to this problem. I was referred to a different environment and as soon as I perfect it, I'll have the 'solution'. :D

However, here is what I came up with. It just barely looks good enough and it's not scaleable (though I'm sure it could have been drawn better). I would also have preferred to create a single spring, and a single mass, which I could then deposit wherever I wanted, but I did not see anything which allowed that in the documentation. But it's done now, and it will have to do:

Code: Select all

\documentclass[11pt,fleqn,reqno]{amsart}
\usepackage{amssymb} %amsthm,amsmath included in amsart documentclass
\usepackage{tikz}

\begin{document}

\begin{center}
\begin{tikzpicture}
%	\draw[step=0.25cm,color=gray] (-1,-1) grid (1,1);
%	\draw [->] (-1.5,0) -- (1.5,0) node [below] {$x$};
%	\draw [->] (0,-1.5) -- (0,1.5) node [left] {$y$};
	
	% Left wall
	\draw[very thick] (0,-.5) -- (0,.5);
	
	% First two springs and masses
	\foreach \x in {0,1} {
		\draw (\x*1.8+0,0) -- (\x*1.8+.25,0);
		\draw (\x*1.8+.375,-.0125) ellipse (1.25mm and 1.25mm)
					(\x*1.8+.500,-.0125) node [above,outer sep=2pt,name=s\x] {$s_\x$} ellipse (1.25mm and 1.25mm)
					(\x*1.8+.625,-.0125) ellipse (1.25mm and 1.25mm);
		\draw (\x*1.8+.75,0) -- (\x*1.8+1,0);
		\draw (\x*1.8+1,0) node[draw,rectangle,name=m\x,anchor=west] {$m_\x$};
	}
	\draw (2*1.8+0,0) -- (2*1.8+.25,0);
	
	% Ellipses
	\foreach \i in {0,...,2} {
		\path (4+\i*.1,0) coordinate (X\i);
		\fill (X\i) circle (1pt);
	}
	
	% Last, n-th spring and mass.
	\foreach \x in {4.35} {
		\draw (\x+0,0) -- (\x+.25,0);
		\draw (\x+.375,-.0125) ellipse (1.25mm and 1.25mm)
					(\x+.500,-.0125) node [above,outer sep=2pt,name=sn] {$s_n$} ellipse (1.25mm and 1.25mm)
					(\x+.625,-.0125) ellipse (1.25mm and 1.25mm);
		\draw (\x+.75,0) -- (\x+1,0);
		\draw (\x+1,0) node[draw,rectangle,name=mn,anchor=west] {$m_n$};
	}
	
	% Very last spring.
	\draw (4.35+1.8,0) -- (4.35+1.8+.25,0);
	\draw (4.35+1.8+.25+.125,-.0125) ellipse (1.25mm and 1.25mm)
				(4.35+1.8+.25+.250,-.0125) node [above,outer sep=2pt,name=sn1] {$s_{n+1}$} ellipse (1.25mm and 1.25mm)
				(4.35+1.8+.25+.375,-.0125) ellipse (1.25mm and 1.25mm);
	\draw (4.35+1.8+.25+.5,0) -- (4.35+1.8+.25+.5+.25,0);
	
	% Right wall
	\draw[very thick] (7.15,-.5) -- (7.15,.5);

	% The original spring and mass.
%	\draw (0,0)  -- (.25,0);
%	\draw (.375,-.0125) ellipse (1.25mm and 1.25mm)
%				(.500,-.0125) node [above,outer sep=2pt,name=s0] {$s_0$} ellipse (1.25mm and 1.25mm)
%				(.625,-.0125) ellipse (1.25mm and 1.25mm);
%					
%	\draw (.75,0) -- (1,0);
%%	\draw (1,-.25) rectangle (2,.25) (1.5,0) node [name=m0] {$m_0$};
%	\draw (1,0) node[draw,rectangle,name=m0,anchor=west] {$m_0$};
\end{tikzpicture}
\end{center}
\end{document}
P.S. How do I easily include the above document in my main text? I tried using \input{graphic}, but that required that I strip the preamble from the graphic.tex.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Shrink text in a picture

Post by localghost »

StupidUser wrote:[…] It just barely looks good enough and it's not scaleable (though I'm sure it could have been drawn better). […]
Of course it is scalable.

Code: Select all

\begin{tikzpicture}[scale=2]
% graphics elements for picture content
\end{tikzpicture}
StupidUser wrote:[…] I would also have preferred to create a single spring, and a single mass, which I could then deposit wherever I wanted, but I did not see anything which allowed that in the documentation. […]
It can be done better (keyword: node styles). And the manual describes that. Due to a lack of time I can't elaborate that at the moment.
StupidUser wrote:[…] How do I easily include the above document in my main text? I tried using \input{graphic}, but that required that I strip the preamble from the graphic.tex.
I don't see the problem. Just include the package into your document preamble and insert the picture code, perhaps wrapped by a figure environment.
Singularity
Posts: 156
Joined: Sat Jan 22, 2011 9:55 pm

Shrink text in a picture

Post by Singularity »

localghost wrote:
StupidUser wrote:[…] It just barely looks good enough and it's not scaleable (though I'm sure it could have been drawn better). […]
Of course it is scalable.

Code: Select all

\begin{tikzpicture}[scale=2][/quote]
The springs and masses come apart when I scale it. I read about nodes, but could not get them working right with the documentation and time frame I had. I really wanted to include multiple graphic elements (three circles in a row, used to represent springs) in one node, and then re-use the node. But couldn't figure it out. Maybe some day.

Also, the circles don't look so good when scaled up. They look like hexagons (which is surely how they're created).

Thanks for helping, ghost.
Post Reply