Text FormattingFormatting Algorithm, Table and Figure Captions and Titles

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
User avatar
NoIdeaNickanme
Posts: 13
Joined: Wed Nov 09, 2011 5:41 pm

Formatting Algorithm, Table and Figure Captions and Titles

Post by NoIdeaNickanme »

Hi!

I'm having trouble with formatting the titles of Algorithm, Table and Figure captions in LaTeX, so, that they all have the same form in text (plain text, small), e.g.:

Algorithm 1: Algorithm name. The caption.

Use of

Code: Select all

\usepackage{chapter}[4]
works on Figure titles and captions only, so I need a solution for Algorithms and Tables.
Please help!

Unfortunately I can not avoid this exact form as it is a rule regarding formatting of my PhD-thesis.

Thanx for your help!
Last edited by NoIdeaNickanme on Fri Nov 18, 2011 8:46 pm, edited 1 time in total.

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Formatting Algorithm, Table and Figure Captions and Titles

Post by localghost »

I don't know a package called »chapter«. Please elaborate what you are doing by a minimal example and explain what you mean with "title" in this context.


Best regards and welcome to the board
Thorsten
User avatar
NoIdeaNickanme
Posts: 13
Joined: Wed Nov 09, 2011 5:41 pm

Formatting Algorithm, Table and Figure Captions and Titles

Post by NoIdeaNickanme »

@localghost I appologise - I misstyped the name of the package - it should have been

Code: Select all

caption
. This fixes formatting issues for Tables and Figures, but not for Algorithms.

In the mean time I temporarily solved the problem of caption formatting and appearance for algorithms by defining my own float for use in combination with Algorithms and matched their settings to those demanded by my faculty (Long story short - LaTeX document must in the end appear identical to their MS Word template). So the full preamble now looks like

Code: Select all

\documentclass[a4paper,11pt,twoside,final,openany]{book}
\usepackage[slovene,english]{babel}
\usepackage[T1]{fontenc}
\usepackage{mathptmx} 
\usepackage{ae,aecompl}
\usepackage[latin2]{inputenc}
\usepackage{amsmath}
\usepackage{amssymb,mathrsfs}   
   \setlength{\mathindent}{1cm}    
\usepackage{graphicx}
\usepackage{url}
\usepackage{psfrag}
\usepackage{units}
\usepackage{fancyhdr}
\usepackage{setspace}
\usepackage[small]{caption}
\usepackage[top=2.2cm, bottom=2.5cm, left=2.5cm, right=2.5cm, bindingoffset=0.7cm]{geometry}
\usepackage{cite}
\usepackage{subfigure}
\usepackage{fixltx2e}  
\usepackage[nottoc,numbib]{tocbibind}
\usepackage{hyperref}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{titlesec}
   \titleformat{\chapter}[hang]{\normalfont\LARGE\bfseries}{\thechapter}{1em}{}
   \titlespacing{\chapter}{0pt}{0pt}{35mm}
   \addto\captionsenglish{\renewcommand\chaptername{}}   
\usepackage{chngcntr}
   \counterwithout{figure}{chapter}    
   \counterwithout{table}{chapter}     
   \counterwithout{equation}{chapter}  
\setcounter{tocdepth}{4}    
\setcounter{secnumdepth}{4}
   \renewcommand\citeleft{[}
   \renewcommand\citeright{]}
\graphicspath{{images/}}
\makeatletter
\usepackage{float}
%%
\newcommand\floatc@simplerule[2]{{\@fs@cfont #1 #2}\par}
\newcommand\fs@simplerule{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@simplerule
  \def\@fs@pre{\hrule height0pt depth0pt \kern4pt}%
  \def\@fs@post{\kern4pt\hrule height0.1mm depth0pt \kern4pt \relax}%
  \def\@fs@mid{\kern8pt}%
  \let\@fs@iftopcapt\iftrue}

\floatstyle{simplerule}
\newfloat{myalgorithm}{thp}{lob}[chapter]
\floatname{myalgorithm}{Algorithm}
\counterwithout{myalgorithm}{chapter}
%%
In document, Algorithms are used as

Code: Select all

\begin{myalgorithm}[h]
\centering
\caption[Title of Algorithm for TOC]{\textit{Title of Algorithm.} Caption of the algorithm.}
\vspace{-9mm}
\begin{algorithm} 
<Algorithm content>
\end{algorithm}
\vspace{-5mm}
\end{myalgorithm}

\listof{myalgorithm}{Index of Algorithms}
It's complicated, but it works...
If there is a simpler solution, I'll gladly use it.
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Formatting Algorithm, Table and Figure Captions and Titles

Post by sommerfee »

NoIdeaNickanme wrote:This fixes formatting issues for Tables and Figures, but not for Algorithms.
The caption package - if loaded - is responsible for the captions of algorithms, too. It just respects the layout rules for "ruled" float types like the algorithm environment, but one can change that, if desired.

Please take a peek at the caption package documentation, section "float package":

http://www.ctan.org/pkg/caption
User avatar
NoIdeaNickanme
Posts: 13
Joined: Wed Nov 09, 2011 5:41 pm

Formatting Algorithm, Table and Figure Captions and Titles

Post by NoIdeaNickanme »

sommerfee wrote:
NoIdeaNickanme wrote:This fixes formatting issues for Tables and Figures, but not for Algorithms.
The caption package - if loaded - is responsible for the captions of algorithms, too. It just respects the layout rules for "ruled" float types like the algorithm environment, but one can change that, if desired.

Please take a peek at the caption package documentation, section "float package":

http://www.ctan.org/pkg/caption
Thanx for the hint! I think this was the only package documentation I didn't read completley when I was constructing the preamble of the document... And it does the trick :)

In the end I simply used newfloat package to declare a new float type offered in floatrow package, which matched the design demanded by the template. It's similar to my own temporary solution, but it shortens the time it takes to generate the pdf document.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Formatting Algorithm, Table and Figure Captions and Titles

Post by localghost »

NoIdeaNickanme wrote:[…] In the end I simply used newfloat package to declare a new float type offered in floatrow package, which matched the design demanded by the template. It's similar to my own temporary solution, but it shortens the time it takes to generate the pdf document.
The floatrow package allows to declare new float types, too. So you don't really need the newfloat package.


Thorsten
Post Reply