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.

Using http://www.latex-community.org/viewtopic.php?f=4&t=251&start=10 I can indent the text, but how to center the figures and table like the image as follow?

enter image description here

My code

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage[a4paper,text={150true mm,224true mm}]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{titlesec}                % define section style
\let\oldsection\section
\renewcommand{\section}{\leftskip=6em \oldsection}
\let\oldsubsection\subsection
\renewcommand{\subsection}{\leftskip=6em \oldsubsection}
\let\oldsubsubsection\subsubsection
\renewcommand{\subsubsection}{\leftskip=6em \oldsubsubsection}
\begin{document}
\section{First section} 
\lipsum[1]
\begin{figure}[htbp]
\centering
\rule{4cm}{2cm}
\caption{figure}\label{fig:1}
\end{figure}
\lipsum[2]
\subsection{First subsection} 
\lipsum[2]
\subsection{Second subsection} 
\lipsum[3]
\subsection{Third subsection} 
\lipsum[4]
\subsection{Last subsection} 
\lipsum[5]
\section{Second section} 
\lipsum[1]
\subsection{First subsection} 
\lipsum[2]
\subsection{Second subsection} 
\lipsum[3]
\subsection{Third subsection} 
\lipsum[4]
\end{document}

get

enter image description here

share|improve this question
2  
Apply \centering within the figure environment should do the trick. If not, please post a fully compilable MWE including \documentclass and the appropriate packages that illustrates the problem. –  Peter Grill Dec 23 '12 at 3:37

2 Answers 2

up vote 12 down vote accepted

Your figures are centered with respect to text width (not text). I suggest a different approach. To get the desired effect you may increase the left margin and push the sections etc into the left margin:

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
%\usepackage[a4paper,text width=110true mm,text height=224true mm]{geometry} % or
\usepackage[a4paper,left=2in,right=1in,top=1in,bottom=1in,height rounded]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyheadoffset[L]{8em}
\usepackage{titlesec}                % define section style
\titleformat{\section}
{\normalfont\Large\bfseries}{\hspace*{-5em}\thesection}{1em}{}
\titleformat{\subsection}
{\normalfont\large\bfseries}{\hspace*{-6em}\thesubsection}{1em}{}
\titleformat{\subsubsection}
{\normalfont\normalsize\bfseries}{\hspace*{-6em}\thesubsubsection}{1em}{}
\titlespacing*{\section}
{0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}
\titlespacing*{\subsection}
{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\titlespacing*{\subsubsection}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex}
\begin{document}
\section{First section} 
\lipsum[1]
\begin{figure}[htbp]
\centering
\rule{4cm}{2cm}
\caption{figure}\label{fig:1}
\end{figure}
\lipsum[2]
\subsection{First subsection} 
\lipsum[2]
\subsection{Second subsection} 
\lipsum[3]
\subsection{Third subsection} 
\lipsum[4]
\subsection{Last subsection} 
\lipsum[5]
\section{Second section} 
\lipsum[1]
\subsection{First subsection} 
\lipsum[2]
\subsection{Second subsection} 
\lipsum[3]
\subsection{Third subsection} 
\lipsum[4]
\end{document}

enter image description here

share|improve this answer

A quick fix is to use a \parbox within your figure environment. I've also made use of the calc package,

\begin{figure}[htbp]
\hfill\parbox{\textwidth - 6em}{%
    \centering
    \rule{4cm}{2cm}
    \caption{figure}\label{fig:1}%
}
\end{figure}

enter image description here

Complete Example:

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage[a4paper,text={150true mm,224true mm}]{geometry}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{titlesec}               % define section style
\usepackage{calc}                   % basic arithmetic operations
\let\oldsection\section
\renewcommand{\section}{\leftskip=6em \oldsection}
\let\oldsubsection\subsection
\renewcommand{\subsection}{\leftskip=6em \oldsubsection}
\let\oldsubsubsection\subsubsection
\renewcommand{\subsubsection}{\leftskip=6em \oldsubsubsection}
\begin{document}
\section{First section} 
\lipsum[1]
\begin{figure}[htbp]
\hfill\parbox{\textwidth - 6em}{%
    \centering
    \rule{4cm}{2cm}
    \caption{figure}\label{fig:1}%
}
\end{figure}
\lipsum[2]
\subsection{First subsection} 
\lipsum[2]
\subsection{Second subsection} 
\lipsum[3]
\subsection{Third subsection} 
\lipsum[4]
\subsection{Last subsection} 
\lipsum[5]
\section{Second section} 
\lipsum[1]
\subsection{First subsection} 
\lipsum[2]
\subsection{Second subsection} 
\lipsum[3]
\subsection{Third subsection} 
\lipsum[4]
\end{document}
share|improve this answer
    
we must change it every float enviornment –  TeX.pig Dec 23 '12 at 6:23
    
Indeed. If you plan on reusing the code, you could define a new control sequence with \newcommand. However, this may be bad practice. @Harish Kumar's solution would be what you are looking for. –  mkota Dec 23 '12 at 6:37

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.