1

I have a problem with loading color packages. I have started my document some time a go and I have around 90 pages. Just now I wanted to add some code listings with colors so I loaded color package. My whole document then got messed around as the spaces between images got changed and the images started traveling to the next page... Is there a way to forbid those color packages like color or xcolor to change the spacing at all? Here is my template:

%% Clear sans, courier

% Klasa:
\documentclass[12pt]{mwart}

% Kodowanie:
\usepackage[utf8]{inputenc}

% odstep w listach
\usepackage[titles]{tocloft}
\addtolength{\cftfignumwidth}{10pt}

% Czcionki:
\usepackage[sfdefault]{ClearSans} %% option 'sfdefault' activates Clear Sans as the default text font
\usepackage[T1]{fontenc}
\usepackage{courier}
\usepackage[T1]{polski}

% Znak euro
\usepackage[official]{eurosym}

% Geometria i style
%\usepackage{showframe} % debug
\usepackage{geometry}
\geometry{a4paper,twoside=true,top=20mm,bottom=30mm,inner=35mm,outer=20mm}
\pagestyle{plain}
\usepackage{float}
\usepackage{afterpage}

% Grafika
\usepackage{graphicx}
\usepackage{epstopdf}

% matma
\usepackage{amssymb,amsmath}

% theoremy
\usepackage{amsthm}

% Stopnie
\usepackage{gensymb}

% Opisy
\usepackage{caption}
\captionsetup[table]{singlelinecheck=off}

% Tabele
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}
\usepackage{array}
\usepackage{makecell}
%\usepackage{color}

% Footnoty
\usepackage{footnote}
\usepackage{perpage} %the perpage package
\MakePerPage{footnote} %the perpage package command

% kody
\usepackage{lipsum}
\usepackage{listings}

% Numerowanie obiektow wedlug rozdzialow
\usepackage{chngcntr}
\AtBeginDocument{\counterwithin{lstlisting}{section}}
\counterwithin{figure}{section}
\counterwithin{table}{section}
\numberwithin{equation}{section}


% Linki
\usepackage{url}
\usepackage{fancyref}

% Listy
\usepackage[ampersand]{easylist}
\ListProperties(Hide=100, Hang=true, Progressive=3ex, Style*=-- ,
Style2*=$\bullet$ ,Style3*=$\circ$ ,Style4*=\tiny$\blacksquare$ )

% Dane:
\title{Uniwersalny inteligentny sterownik silników do zastosowań przemysłowych}
\author{Łukasz Przeniosło}

% Zmienne srodowiskowe:
\newcommand{\paperTitlePl}{UNIWERSALNY INTELIGENTNY STEROWNIK SILNIKÓW DO ZASTOSOWAŃ PRZEMYSŁOWYCH}
\newcommand{\paperTitleEn}{UNIVERSAL INTELIGENT MOTOR DRIVER FOR INDUSTRIAL APPLICATIONS}
\newcommand{\topicChooseDate}{01.08.2015 r.}
\newcommand{\topicAcceptationDate}{01.06.2016 r.}
\newcommand{\tocLessLeft}[1]{\textsc{\textbf{\large \flushleft{#1}}} \vspace{3mm} \\ \indent }
\newcommand{\tocLessLeftNorm}[1]{\textsc{\textbf{\normalsize \flushleft{#1}}} \vspace{0mm} \\ \indent }
\newcommand{\tocLessCenter}[1]{\textsc{\textbf{\large \centerline{#1}}} \vspace{3mm} \\ \indent }
\newcommand{\insertImg}[3]{%
\begin{figure}[h]
    \centering
    \includegraphics[height=50mm]{#1}
    \caption{#2} \flushleft{Źródło: Na podstawie \cite{#3}}
    \label{#1}
\end{figure}
}
\newcommand{\insertImgSetSize}[4]{%
\begin{figure}[h]
    \centering
    \includegraphics[height=#2mm]{#1}
    \caption{#3} \flushleft{Źródło: Na podstawie \cite{#4}}
    \label{#1}
\end{figure}
}
\newcommand{\insertTab}[5]{%
\begin{savenotes}
    \begin{table}[h]
        \flushleft{Źródło: Na podstawie \cite{#4}} \\
        \vspace{2mm}
        \centering
        \begin{tabular}{#1} 
        #2
        \end{tabular}
        \caption{#3}  
        \label{#5}
        \floatstyle{plaintop}
    \end{table}
\end{savenotes}
}

% Zmienic jesli jednak Engineering -.- ...
\newcommand{\firma}{{Mechatronic Systems}}

% twierdzenia
\newtheorem{defn}{Definicja}[section]

% Indeksowanie w pdfie wyjsciowym
\usepackage{hyperref}

% Naprawienie referencji do figur i tabel
\renewcommand{\theHfigure}{figure.section.thesection.\thefigure}

% START:
\begin{document}

some text text text

\insertImgSetSize{example-image-a}
    {40}
    {1st image}
    {badcite}

some text text text

\insertImgSetSize{example-image-a}
    {50}
    {1st image}
    {badcite}

some text text text

\insertImgSetSize{example-image-a}
    {60}
    {1st image}
    {badcite}

some text text text

\insertImgSetSize{example-image-a}
    {50}
    {1st image}
    {badcite}



\end{document}

Edit: I have updated the example, it is ready to be pasted and run. Please notice how color package is commented out in line 53. Compile the code and see the document. Then uncomment the color package and compile, you will see the spacing increase. Is there a way to disable this spacing increase?

  • ...I wonder how we can recreate this issue locally... do you mind helping us do that so we can see what you mean by "the addition of color moved things around... messed it up."? We would need something that replicates the problem. – Werner Jun 22 '16 at 20:11
  • Sorry, it happens after I add \usepackage{color} or \usepackage{xcolor} – Łukasz Przeniosło Jun 22 '16 at 20:12
  • That's fine... so what's in theorems.tex? Without it, we can't really compile your document and see what the effect of the changes are. – Werner Jun 22 '16 at 20:13
  • Sorry again... All that file contains is one line: \newtheorem{defn}{Definicja}[section] – Łukasz Przeniosło Jun 22 '16 at 20:14
  • So you're saying I can copy-and-paste the code in your question that contains only a single figure, and see how the "document gets messed up" when I uncomment the line \usepackage{color}? – Werner Jun 22 '16 at 20:16
  • 1
    Not really, as documented in the color package documentation it can affect spacing in some cases. unrelated but {\large \flushleft{#1}}} will not make things go flush left, unless #1 ends in a blank line, \centerline shouldn't really be used in latex, \flushleft{Źródło: Na podstawie \cite{#4}} is wrong \flushleft does not take an argument it affects the rest of the current group and \afterpage{\null \thispagestyle{empty} \newpage} is i assume intended to do \cleardoublepage but using a pagestye empty, there are far safer ways to do that! – David Carlisle Jun 22 '16 at 20:20
  • I am not very latex savy... Since the procedures I used worked I didnt give more thought about it. I can bet this is not the best latex code as you suggested. Do you think the spacing problem lies in my \insertImgSetSize macro? I use it for figures in my whole document. – Łukasz Przeniosło Jun 22 '16 at 20:28
  • I can only comment on the code I can see. For all we know the spacing problem is code in theorems.tex or any other part you have not shown. the question is not answerable in this form. take a copy of the document and make a small single-file document that shows the problem and delete everything else can you really not demonstrate the problem without the easylist package or the ClearSans, etc. Put yourself in the position of someone who is going to run your docuemnt with tracing turned on and make it easy for them, not make them have to step over gigabytes of unrelated log data. – David Carlisle Jun 22 '16 at 20:33
  • one obvious thing wrong with \insertImgSetSize is the missing % after \end{figure} that could produce spurious white space in some cases. – David Carlisle Jun 22 '16 at 20:35
  • I was not deleting any packages because I have noticed when using latex that packages that should have nothing to do with something, often affect other modules. – Łukasz Przeniosło Jun 22 '16 at 20:35
  • But you can easily test that as you can delete the packages and see if the problem is still there. So you don't need to guess. No one else can do that as no one else has an example that demonstrates the problem. – David Carlisle Jun 22 '16 at 20:36
  • Have you tried any of the suggestions here or here? – Jeffery Shivers Jun 22 '16 at 20:47
  • I have checked the links you have procided. The problem is that i havent written a single line of code containing stuff from color package. The spacing changes as soon as i unclude the package. – Łukasz Przeniosło Jun 23 '16 at 06:06
  • If you remove the line \input{theorems.tex} then your example may be run. I then added \usepackage{color} but saw no change in formatting. Please fix the example so that it runs without error, and adding color changes something. – David Carlisle Jun 23 '16 at 22:36
  • I will do that first thing in the morning, thank you. Could you only tell me how one could onsert example images? I know it included word example and google is hard to trick on this one. – Łukasz Przeniosło Jun 23 '16 at 23:17
  • @DavidCarlisle I have edited my question with a ready to pase example. – Łukasz Przeniosło Jun 24 '16 at 13:36

1 Answers1

1

You're using wrongly \flushleft

\newcommand{\insertImg}[3]{%
\begin{figure}[h]
    \centering
    \includegraphics[height=50mm]{#1}
    \caption{#2}\label{#1}
    \raggedright Źródło: Na podstawie \cite{#3}
\end{figure}
}
\newcommand{\insertImgSetSize}[4]{%
\begin{figure}[h]
    \centering
    \includegraphics[height=#2mm]{#1}
    \caption{#3}\label{#1}
    \raggedright Źródło: Na podstawie \cite{#4}
\end{figure}
}
\newcommand{\insertTab}[5]{%
\begin{savenotes}
    \begin{table}[h]
        \raggedright Źródło: Na podstawie \cite{#4}\\
        \vspace{2mm}
        \centering
        \begin{tabular}{#1} 
        #2
        \end{tabular}
        \caption{#3}  
        \label{#5}
        \floatstyle{plaintop}
    \end{table}
\end{savenotes}
}
egreg
  • 1,121,712
  • Thank you... Can I ask what was really wrong with flushleft? – Łukasz Przeniosło Jun 24 '16 at 21:24
  • 1
    @ŁukaszPrzeniosło \flushleft exists only because of the flushleft environment. It should never be used in the body of the document, but only, with care, in the definition of other *environments* (not macros), in the “begin” part. In this case it should always be followed by \endflushleft in the “end” part. The corresponding declaration is \raggedright. – egreg Jun 24 '16 at 21:29