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.
Related
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:
If I include [p] in the placement specifier of a \begin{figure} environment, figure floats may be placed on a dedicated page. However, at least in the "book" document class, floats are centered vertically on those pages.
How do I force all "pages-o-floats" to be aligned to the top margin (just like normal text pages)?
I believe your answer is in the UK TeX FAQ:
\#fptop defines the distance from the top of the page to the top of the first float
The simple fix is to reset \#fptop in your preamble:
\makeatletter
\setlength{\#fptop}{0pt}
\makeatother
However, you might find that this is a bit too high, so you might want something like 5pt instead. (Anyway, the FAQ entry is well worth reading; it explains in more depth what's going on than I am here.)
can you not use the [t] specifier instead of [p]?
I am looking for a simple way to control the width of a \caption{} inside a float in LaTeX without using the {caption} package. Any clues?
(EDIT): The problem I am having is that the built-in captions are too narrow.
In general, to control the width of objects in TeX, you can use a minipage, for instance:
\begin{minipage}[t]{1.85in}
\caption{ Why would you eat a pickle? }
\end{minipage}
However, with a caption you might need to do something different as it could very well be a macro.
To change the formatting of the standard LaTeX classes without using a package, you need to look at the source of the standard LaTeX classes and alter the original definitions in your own document. Printing captions is done by the macro \#makecaption, which has definition (in article.cls):
\long\def\#makecaption#1#2{%
\vskip\abovecaptionskip
\sbox\#tempboxa{#1: #2}%
\ifdim \wd\#tempboxa >\hsize
#1: #2\par
\else
\global \#minipagefalse
\hb#xt#\hsize{\hfil\box\#tempboxa\hfil}%
\fi
\vskip\belowcaptionskip}
If you wrap the whole thing in a minipage environment (as suggested to be done manually in the other answers), you should get the results you want.
Is it easier than loading a package? Not really, but it can be instructive.
There's nothing too magical about \caption; it just consults a figure/table number and than formats your text at a font and size that the document class likes. So you can control its width the same way you'd control the width of any text:
Wrap the \caption{...} in a \parbox or a \begin{minipage}...\end{minipage}.
A font I am using does not have the slanted/oblique variant to it in LaTeX (NB: not italics), and I would like to have slanted text in places.
Is there an easy way to slant text without having to generate entirely new font files and such?
One suggested solution was to do:
\renewcommand{\textsl}[1]{\tikz[baseline=(X.base)] \node[xslant=0.2231153] (X) {#1};}
This works well for one or two words, but tikz nodes don't break across lines, so it's not adequate, for, say, a theorem environment.
Obviously, a quick-and-dirty method will not give exceptional kerning or spacing, but I am not concerned about that. However, a 13 degree shear/slant would be desirable.
You can do this easily in XeLaTeX:
\usepackage{fontspec}
...
\fontspec[ItalicFont=*,ItalicFeatures=FakeSlant]{Minion Pro}
Highly undesirable, however, if there's any chance you can get a real italic.
Update: why undesirable? Because font outlines are not designed to be distorted! Any sort of transformation besides linear scaling in both directions will change the relationship between the inner/outer curves of the letters, effectively going against the wishes of the font designer.
If you want to highlight something in a different font than the roman and not use italic, try something completely different like a harmonising sans serif, for example.
Use a font that does have italics. Standard fonts are best unless you're in marketing.
I use LuaLaTeX, but the following should also work with XeLaTeX. LuaLaTeX, from my experience, is fully backward compatible with good old LaTeX, and it's only marginally slower. And making new, clever macros is a breeze. Anyhow, enough proselytizing.
This is pulled almost directly from one of my documents. Some of it is hackish, yes, but it suits my needs well - and the results are quite respectable.
\usepackage{relsize} % For \texttt definition below
\usepackage{fontspec}
\setmainfont% Minion Pro, not redistributable?
[Ligatures=TeX,
SlantedFont=*,
SlantedFeatures={FakeSlant=0.2},
BoldSlantedFont=* Bold,
BoldSlantedFeatures={FakeSlant=0.2}
]{Minion Pro}
\setsansfont% Linux Biolinum O % SIL Open Font License
[Ligatures=TeX,
Extension=.otf,
BoldFont=fxbb,
ItalicFont=fxbri,
BoldItalicFont=fxbri,
BoldItalicFeatures={FakeBold=1.5}, % Note: This is not currently working in LuaTeX!
SlantedFont=fxbro,
BoldSlantedFont=fxbbo
]{fxbr}
\setmonofont[Ligatures=TeX]{DejaVu Sans Mono} % "Free License" No General Restictions
\makeatletter
\let\old#texttt\texttt
\renewcommand{\texttt}[1]{{\smaller\old#texttt{#1}}}
\makeatother
Here are some macros for shearing, but that will not be what you want either, I guess.
\usepackage{graphicx}
%\hshearbox{vertical_prescale_times_shearfactor}{one_divide_by_shearfactor}{content}
% an initial vertical downscale is often necessary for a 3d projection
\newcommand{\hshearbox}[3]{\scalebox{0.866025}[#2]{\rotatebox{210}%
{\scalebox{1.73205}[-0.57735]{\rotatebox{60}{\scalebox{-1.1547}[#1]{#3}}}}}}
%\vshearbox{horizontal_prescale_times_shearfactor}{one_divide_by_shearfactor}{content}
% an initial horizontal downscale is often necessary for a 3d projection
\newcommand{\vshearbox}[3]{\scalebox{#2}[0.866025]{\rotatebox{210}%
{\scalebox{-0.57735}[1.73205]{\rotatebox{60}{\scalebox{#1}[-1.1547]{#3}}}}}}
The XeLaTeX/fontspec answer mentioned above somehow wouldn't work for me, so I came up with this:
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\newcommand{\slsc}[1]{\fontspec[SmallCapsFeatures={FakeSlant=0.6}]{Linux Libertine O}\textsc{#1}\fontspec[]{Linux Libertine O}}
\begin{document}
normaltext
\textsc{textsc}
\slsc{textslsc} % this will produce slanted small caps
\end{document}
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}