I've been looking for a more elegant solution to the following typesetting problem. Consider those banners found in print media where the text is aligned like:
B I G T E X T
small text small text small text
m o r e m e d i u m t e x t
The font sizes are adjusted so that the height is scaled down for longer lines of text such that each line has equal width. I've written a small script that runs each line separately, compiles, crops the resulting pdf and then \includegraphics each in a table. This gives the desired effect but requires an both an outside script and pdfcrop (which only crops to a white bounding box). Since much of LaTeX is self-aware, I imagine it would be possible to have it recognize the width of a box and scale it appropriately so that any text fits exactly into the desired width.
Any thoughts or ideas on how a pure LaTeX implementation might work?
EDIT As a supplement to the suggested solution by AVB (since large code in comments looks awful), I've posted below the code used so that others may find it easily.
\documentclass[]{article}
\usepackage[pdftex]{graphicx}
\begin{document}
\begin{table}[l]
\resizebox{10cm}{!}{BIG Text} \\
\resizebox{10cm}{!}{small text small text small text} \\
\resizebox{10cm}{!}{Medium Text Medium Text}
\end{table} \end{document}
First, read the TeX FAQ entry titled Changing the space between letters. Depending on your circumstances, the packages and recommendation in that FAQ may suffice.
Also, take a look at the \scalebox and \resizebox commands in the graphicx package. They do what the names imply.
I'm sure that this could be improved upon, and due to different font implementations at different sizes then it isn't going to be exact, but here's a quick-and-dirty way to do it:
\documentclass[10pt]{article}
\usepackage{pgfmath}
\usepackage{anyfontsize}
\newlength{\mywidth}
\newlength{\testwidth}
\setlength{\mywidth}{4in}
\newcommand{\fixedwidth}[1]{%
\settowidth{\testwidth}{#1}%
\pgfmathsetmacro{\x}{round(\mywidth/\testwidth * 10)}%
\pgfmathsetmacro{\y}{round(\mywidth/\testwidth * 15)}%
\bgroup\fontsize{\x pt}{\y pt}\selectfont#1\egroup}
\begin{document}
\fixedwidth{hello world}
\fixedwidth{greetings earthlings}
\end{document}
In practice, it's a little less than the 4in, but the two lines of text do get scaled to the same amount.
Check out the package textfit. Usage:
\scaletowidth{width}{text}
or
\scaletoheight{height}{text}
Related
LaTeX seems to have a preference for placing figures together on a page, and placing surrounding text on a separate page. Can I somehow change that balance a bit, as I prefer figures to break up the text to avoid too black text-heavy pages.
Example:
\section{Some section}
[Half a page of text]
\begin{figure}
[...]
\caption{Figure text 1}
\end{figure}
[Half a page of text]
\begin{figure}
[...]
\caption{Figure text 2}
\end{figure}
[More text]
So what LaTeX usually does is to stack the two half pages of text on a single page, and the figures on the following page. I believe this really gives a bad balance, and bores the reader. So can I change that somehow?
I know about postfixing the \begin{figure} with [ht!], but often it does not really matter. I would like to configure the balancing algorithms in LaTeX to naturally prefer pages with combined figures and text.
Try putting the following in your preamble.
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{2}
\setcounter{totalnumber}{4}
\renewcommand{\topfraction}{0.85}
\renewcommand{\bottomfraction}{0.85}
\renewcommand{\textfraction}{0.15}
\renewcommand{\floatpagefraction}{0.7}
You might play with those numbers a little to suit your own preferences. Some explanations of the different parameters are given here.
Try to tune floats positioning with:
\begin{figure}[tb] for figures that fit well in a page with text (say, half of the text height for the figure and the other half for the text)
\begin{figure}[p] for floats large enough to require a dedicated page.
Also, you can place some "barriers" for floats positioning with the packages placeins or afterpage.
Try
\makeatletter
\#colnum 1 % Or 2. It is the max of the float insertions at the top of the page.
\makeatother
I am trying to determine how to get the height on a block of latex output (not the whole document, and not the code..but rather a block of output). As an example of what I am trying to accomplish: i were to have the latex code
$\sum_{i=0}^\infty \frac{1}{n}>\infty$ \newline hello world \newline hello universe
The height of the above block of text is dependent on a number of things-font, margin size, and of course what the text is, as changing any of these parameters changes how many inches that output would be, but with default formatting its output would be something like 2 inches high.
I am hoping there is a package that does this!
Usually, the trick is to put whatever you want to measure into a box and then simply not typeset the box, but measure it:
\newdimen\height
\setbox0=\hbox{\Huge Hello, World!}
\height=\ht0 \advance\height by \dp0
The height is: \the\height
I think this will work:
\newlength{\somenamehere}
\settoheight{\somenamehere}{\hbox{...}}
Where ... is your content you like to measure. And you can then use \somenamehere as the height of that content.
Example:
\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{babel}
\begin{document}
\newlength{\heightofhw}
\settoheight{\heightofhw}{\hbox{Hello World!}}
Value = \the\heightofhw
\end{document}
Will output:
Value = 6.8872pt
Note:
Values of lengths are stored as points, and 1 inch ≈ 72.27 pt
This does not require any additional packages.
Update:
Use \hbox to correctly calculate the height of a different sized environment, but it won't work with newlines :-(
I am writing a personal statement in latex. I don't want the big margin at the top of the page not big title taking a lot of space. I just like to make the layout compact but still clearly spaced with title, name and other necessary information, since there may be restriction on the number of pages. One example would be http://www.hsc.unt.edu/education/CIM/Documents/PS-Sample2_000.pdf. I wonder where to find some good latex templates or examples?
Thanks and regards!
I would use the geometry package to establish the desired margins. To get the margins in your sample document, try:
\usepackage[left=1in,right=1in,top=1in,bottom=1in]{geometry}
Your next requirement was to fix the title block. LaTeX uses the internal command \#maketitle to format the title block. You can redefine this as you like. To achieve the same title block style as in the sample document, use:
\usepackage[svgnames]{xcolor}% provides colors for text
\makeatletter% since there's an at-sign (#) in the command name
\renewcommand{\#maketitle}{%
\begin{center}
\parskip\baselineskip% skip a line between paragraphs in the title block
\parindent=0pt% don't indent paragraphs in the title block
\textcolor{red}{\bf\#title}\par
\textbf{\#author}\par
%\#date% remove the percent sign at the beginning of this line if you want the date printed
\end{center}
}
\makeatother% resets the meaning of the at-sign (#)
The \#title, \#author, and \#date commands will print the title, author, and date. You can use whatever formatting commands you like to set the text in bold, different colors, etc.
Put all of the above commands in the preamble of the document. The preamble is the space between \documentclass and \begin{document}.
\documentclass{article}
% this is the preamble
% put all of the above code in here
\title{Personal Statement}
\author{Tim}
\begin{document}
\maketitle% prints the title block
Emergency medicine has always been a passion of mine\ldots
\end{document}
Attempt #1: I've used the following style file, which I call cramp2e, for similar purposes. It is probably not right for you, but have a look:
\oddsidemargin -1cm
\evensidemargin -2cm
\topmargin 1cm
\textheight 24cm
\textwidth 19cm
\headheight 0cm
\headsep .7cm
\footskip .7cm
\parskip .2cm
\paperheight 25cm
\setlength\voffset{-.33in}
\setlength\hoffset{-.25in}
Any good?
Postscript This is for A4 size paper.
A slightly less LaTeX-ey solution would be to not use the \maketitle command. A couple of times I've simply used this as my title(marginsize helps too).
Set up smaller margins:
\documentclass{article}
\usepackage{anysize}
\marginsize{1cm}{1cm}{1cm}{1cm}
(EDIT: 1cm might be even better..)
Minimal title:
\begin{document}
\begin{center}
\section*{My Document Title}
\today
\end{center}
% content goes here
\end{document}
The result looks something like:
I have a question on inserting images into a LaTeX document. I try to insert images using the keyboard short cut: Ctrl-Alt-G and I'm able to insert images. But the compiled pdf document shows all the images at the end, whereas I want to interleave images with text. Something like the following:
Text1
Image1
Text2
Image2
Text3
Image3
I try to insert images at right positions i.e. in between text, but on compilation, they all appear at the end. I have tried different options provided on the image insertion UI but same result.
Any idea where I'm going wrong.
Related SO question.
You'll have to use graphicx package:
\usepackage{graphicx}
and then you just use \includegraphics
\includegraphics{myfig.pdf}
\includegraphics[width=60mm]{myfig.png}
\includegraphics[height=60mm]{myfig.jpg}
\includegraphics[scale=0.75]{myfig.pdf}
\includegraphics[angle=45,width=52mm]{myfig.jpg}
Try downsizing the images. Maybe they are too large and so they are moved to the end of the document..
Hope it helps.
What code did you use for the \figure environment? In most cases the "h" option should at least help a little bit there.
This is a FAQ: "Moving tables and figures in LaTeX". Note especially the third dot point, which relaxes some of the restrictions LaTeX uses to position floats.
That's the best answer I can give without seeing an example of how large your floats are and how you're inserting them into the document. Provided that they're reasonably-sized, you should have no problem with
\begin{figure}[htbp]
\includegraphics{myfig}
\caption{...}
\label{fig:myfig}
\end{figure}
And note that if the float is too large to fit then it will move to a subsequent page -- this is the whole idea behind getting LaTeX to help you with the formatting. You certainly don't want to end a page prematurely just because there's a figure coming up next that otherwise doesn't fit.
Maybe this can help you in general...I just hate the LaTeX way of making everything too advanced (flexible) at all times.
Beside, the source looks really awful.
It will not solve you initial problem, but since it will be easier to change size of each image you can at least try...
% Easy image insert
% use as \img{imagename}{caption}{label}
% will insert image with with 70% of textwidth
% change below for other width
\newcommand{\img}[3]{
\begin{figure}[!ht]
\centering
\includegraphics[width=0.7\textwidth]{#1}
\caption{#2}
\label{fig:#3}
\end{figure}
}
\img{myimage}{has this caption}{and_this_label}
the label is automatically prefixed with fig:.
Good luck!
/C
Using [!t] and [!h] in the figure environment, rather than [t], [h] etc seems to help, though I've yet to find a surefire way to get large images in sensible places. Sometimes it works half way through a document, othertimes it doesn't.
Sometimes just changing the width or height using an option to the includegraphics statement (square brackets before the filename a.k.a \includegraphics[width=foo]{}) will do the trick.
\begin{figure}[H!]
\includegraphics{myfig}
\caption{...}
\label{fig:myfig}
\end{figure}
Use H! to denote that you want your picture right there.
\documentclass{article}
\usepackage{graphicx}
\begin{document}
text
\begin{figure}[tbh]
\centering
\includegraphics[width=0.4 \textheight]{ & directory path of jpg. width defines the width of the page and one one can put in its place height which is text page height }
\caption{name of the jpg}
\end{figure}
% it worked for me.
\end{document}
In LaTeX figures, one can use \textwidth and \columnwidth to specify sizes of the graphic relative to the size of surrounding text, e.g.
\includegraphics[width=.5\textwidth]{myimage}.
I would like to easily switch from onecolumn to twocolumn template (and back) without the figure growing too large for onecolumn template. For twocolumn template (where \columnwidth is roughly half the \textwidth), I would like to have something like:
\includegraphics[width=.9\columnwidth]{myimage}.
and for onecolumn template (where \columnwidth and \textwidth are equal):
\includegraphics[width=.5\textwidth]{myimage}.
Now, I figured I could limit this using some kind of a min operator:
\includegraphics[width=min(.5\textwidth,.9\columnwidth)]{myimage} but this is invalid syntax. Is there something like this to solve this problem, possibly through the use of LaTeX macro system?
Although it's possible to write this sort of macro, I wouldn't want to hardcode it into each figure; how about something like this
\makeatletter
\newlength \figwidth
\if#twocolumn
\setlength \figwidth {0.9\columnwidth}
\else
\setlength \figwidth {0.5\textwidth}
\fi
\makeatother
and then use
\includegraphics[width=\figwidth]{myimage}
to insert the graphic.
\textwidth is the horizontal width of the page body and not really appropriate for your purposes.
\linewidth is the width of the current line; it will be updated appropriate to columns, indentation, etc.
The following paragraph produces a picture that should precisely fit the entire line width (i.e. no overful warning):
\noindent\includegraphics[width=\linewidth]{myimage}
If you prefer small margins on the left and right, you can use:
\begin{center}
\includegraphics[width=.9\linewidth]{myimage}
\end{center}
Or, if you want to specify the margins in an absolute size:
\usepackage{calc}
...
\begin{center}
\includegraphics[width=\linewidth-20pt]{myimage}
\end{center}
Hmm... the code above (\if#twocolumn etc.) is not working for me at all. No idea why not. :( tetex on osX using fink. Trying to use revtex4, so perhaps that's the problem. I really like the idea of this type of change because I'm going to be dorking with widths etc. for my thesis and various journal articles, and to have these distances specified with a macro may be helpful for these types of conversions.
Any comments greatly appreciated!
-Allen
Somebody else who is more familiar with this will probably answer, but note that you would also need to change your figure type to be figure* if you are going two-column.