\documentclass[a4paper,
pointlessnumbers,
%draft,
parskip=half,
automark
]{scrartcl}
\setlength{\parindent}{0pt}
\usepackage[a4paper, left=2.2cm, right=2.2cm, top=2.5cm, bottom=2.5cm,]{geometry}
\usepackage{scrpage2}
\clearscrheadfoot
\pagestyle{scrheadings}
\usepackage[ngerman]{babel}
\usepackage[pdftex]{graphicx,color}
\usepackage[utf8]{inputenc}
\usepackage{amssymb,amsmath,amsthm, amsfonts}
\usepackage{latexsym}
\usepackage[decimalsymbol=comma]{siunitx}
\usepackage{booktabs}
\usepackage{tabulary}
\usepackage[dvipsnames]{xcolor}
\usepackage[centerlast,small,sc]{caption}
\usepackage{here}
\usepackage{siunitx}
\usepackage{titling}
\usepackage{subfigure}
\usepackage{hyperref}
\renewcommand{\i}{\mathrm{i}}
\newcommand{\e}{\mathrm{e}}
\newcommand{\diff}{\mathrm{d}}
\newcommand{\figref}[1]{Abb. \ref{#1}}
\newcommand{\ImNew}{\operatorname{Im}}
\newcommand{\ReNew}{\operatorname{Re}}
\newcommand{\xdot}{\! \, \cdot \! \,}
\newcommand{\funof}[1]{{\color{gray}(#1)}}
%Dokument
\begin{document}
\setcounter{page}{0}
\maketitle
\thispagestyle{empty} % Keine Seitenzahl auf Titelseite
\ofoot{\upshape\thepage}
\clearpage
%Inhaltsverzeichnis
%\thispagestyle{empty}
\tableofcontents
\clearpage
%Hauptdokument
\pagenumbering{arabic}
\ihead{\upshape\scriptsize \leftmark}
\ohead{\upshape\scriptsize \thetitle}
%\ifoot{\upshape \scriptsize}
\ofoot{\upshape\thepage}
\begin{center}
\includegraphics[scale=0.2]{SC Bilder/sc1.png}
\label{fig:Veranschaulichung Erzeugung von polarisiertem Licht}
\end{center}
\caption{Veranschaulichung der Erzeugung von linear polarisierten Lichgt und zirkular polarisiertem Licht}
\end{document}
- 62,593
1 Answers
Let's start by making your code more minimal:
\documentclass{scrartcl}
\usepackage{graphicx}
\begin{document}
\begin{center}
\includegraphics[scale=0.2]{example-image}
\label{fig:Veranschaulichung Erzeugung von polarisiertem Licht}
\end{center}
\caption{Veranschaulichung der Erzeugung von linear polarisierten Lichgt und zirkular polarisiertem Licht}
\end{document}
If you compile this code, you end up with the following error message:
! LaTeX Error: \caption outside float.
You get this error message, since you can only use the \caption command inside of a floating environment such as figure or table.
So let' s replace center with figure and move the caption command inside of the \figure environment. For correct cross-referencing, make sure the \labelis placed after the corresponding \caption. In the following MWE, I also added \centering in order to horizontally center the image:
\documentclass{scrartcl}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\includegraphics[scale=0.2]{example-image}
\caption{Veranschaulichung der Erzeugung von linear polarisierten Licht und zirkular polarisiertem Licht}
\label{fig:Veranschaulichung Erzeugung von polarisiertem Licht}
\end{figure}
\end{document}
For some background information on floats and how you can control their placement, take a look a the following questions and their answers.
How to influence the position of float environments like figure and table in LaTeX?
Keeping tables/figures close to where they are mentioned
If you absolutely don't want your image to move away from where it was mentioned in the code, you could use the following approach based on the \captionof command from the caption package. However, please be aware that large white spaces can occur in your document, especially if an image is too large for the remaining space on a page:
\documentclass{scrartcl}
\usepackage{graphicx}
\usepackage{caption}
\begin{document}
\begin{center}
\includegraphics[scale=0.2]{example-image}
\captionof{figure}{Veranschaulichung der Erzeugung von linear polarisierten Licht und zirkular polarisiertem Licht}
\label{fig:Veranschaulichung Erzeugung von polarisiertem Licht}
\end{center}
\end{document}
A final remark on the \label command: Although spaces are allowed in a lable, I would recommend not using them. Personally, I'd also use a shorter, but still descriptive key, for example something like \label{fig:Erzg-pol-Licht}. Some background on allowed characters inside of a \label can be found here:
What are the valid names as labels?
- 62,593
-
Thank you so so much Sir! It really helped me!!! Have a great day! – NirvanicUniverse Jun 13 '21 at 09:55
subfigurepackage is considered obsolete. You may want to usesubcaptionorsubfiginstead. – leandriis Jun 13 '21 at 07:52decimalsymbolwhich you added to the options ofsiunitxwas an option used in version 1 (prior to 2010) of the package. Similarly,scrpage2is considered obsolete since 2015 and the package author recommends usingscrlayer-scrpageinstead. – leandriis Jun 13 '21 at 07:57