# Horizontal alignment in minipage

My CODE:

\documentclass[12pt, letterpaper]{article}
\usepackage[
a4paper,top=1in,bottom=1in,left=0.7in,right=0.7in,headheight=14.5pt,]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{forest}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}
\noindent\textbf{Solution: 5}

\noindent\begin{minipage}[t]{0.45\textwidth}
In $\triangle ABC,$ $CD\perp AB$ and $\angle D= 90^{\circ}$
Given that,
\begin{align*}
\cos A &=\cos B\\[6pt]
\therefore\;\;\dfrac{AD}{AC}&=\dfrac{BD}{BC}\\[6pt]
\therefore\;\;\dfrac{AD}{BD}&=\dfrac{AC}{BC}= k\quad (\text{say})\\[6pt]
\therefore\;\;AD&=kBD \tag{1}\\[6pt]
AC&=kBC \tag{2}
\end{align*}
\end{minipage}\hspace{\fill}%
\begin{minipage}[t]{0.45\textwidth}
\vspace{0pt} % to anchor the minipage at the very top
\raggedleft
\begin{tikzpicture}

\tkzDefPoint(0:0){A}
\tkzDefPoint(0:6){B}
\tkzDefPoint(45:4){C}
\tkzLabelPoint[above](C){$C$}
\tkzLabelPoint[below,yshift=-0.8mm](B){$B$}
\tkzLabelPoint[below,yshift=-0.8mm](A){$A$}

\tkzDrawSegment[black!60!black](C,A)
\tkzDrawSegment[black!60!black](A,B)
\tkzDrawSegment[black!60!black](C,B)

\tkzDrawAltitude[color=black](A,B)(C)
\tkzGetPoint{D}%Get the point of intersection
\tkzLabelPoint[below](D){$D$}
\tkzMarkRightAngle(C,D,A)%Mark with a right angle symbol

\end{tikzpicture}
\end{minipage}
\end{document}


Question: The mini page that i have made, both parts are not in proper horizontal alignment. Where do i make mistake please guide me. i am facing same problem frequently while using mini page environment. this type of question has already asked by me before and find the solution of that problem but when i use that code for another examples it does not work.

• the first minipage is aligned on the baseline of the first line of text but the second one, as you note in comments you have moved the alignment to the top edge of the box \vspace{0pt} % to anchor the minipage at the very top Commented Mar 3, 2016 at 9:59
• Sir i have upload the desire output with my modified MWE please sir do some correction in it Commented Mar 3, 2016 at 10:50
• Sir, this is my humble request to you. coz my work is stopped due to this problem. please it will be a great help to me Commented Mar 3, 2016 at 10:56
• If you put \fbox{\begin{tikzpicture}...\end{tikzpicture}} you will see this which shows the problem, the tikzpicture is aligned at the top but is much bigger than the triangle. I have no idea why, you could replace \vspace{0pt} by \vspace{-3cm} or whatever looks right, but someone else can possibly tell you how to get a better natural size for the tikz Commented Mar 3, 2016 at 11:51
• It's ok sir. Waiting for a solution by someone else Commented Mar 3, 2016 at 15:13

## 2 Answers

The trouble comes from the line

\tkzDrawAltitude[color=black](A,B)(C)


That add extra space on top of the triangle. In this document http://texdoc.net/texmf-dist/doc/latex/tkz-euclide/tkz-euclide-screen.pdf page 87 you have an example using this command. They add a line at the beginning of the tikzpicture to make it working without this extra space.

\tkzInit[xmin=-1,xmax=7,ymin=-1,ymax=4]\tkzClip


For your example, I prefer use two columns instead of two minipage? This code give you the expected result:

\documentclass[12pt, letterpaper]{article}
\usepackage[
a4paper,top=1in,bottom=1in,left=0.7in,right=0.7in,headheight=14.5pt,]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{forest}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usepackage{multicol}
\usetkzobj{all}
\begin{document}

\begin{multicols}{2}
\noindent\textbf{Solution: 5}

In $\triangle ABC,$ $CD\perp AB$ and $\angle D= 90^{\circ}$
Given that,
\begin{align*}
\cos A &=\cos B\\[6pt]
\therefore\;\;\dfrac{AD}{AC}&=\dfrac{BD}{BC}\\[6pt]
\therefore\;\;\dfrac{AD}{BD}&=\dfrac{AC}{BC}= k\quad (\text{say})\\[6pt]
\therefore\;\;AD&=kBD \tag{1}\\[6pt]
AC&=kBC \tag{2}
\end{align*}
\columnbreak
\begin{center}
\begin{tikzpicture}[auto]
\tkzInit[xmin=-1,xmax=7,ymin=-1,ymax=4]\tkzClip
\tkzDefPoint(0:0){A}
\tkzDefPoint(0:6){B}
\tkzDefPoint(45:4){C}
\tkzLabelPoint[above](C){$C$}
\tkzLabelPoint[below,yshift=-0.8mm](B){$B$}
\tkzLabelPoint[below,yshift=-0.8mm](A){$A$}
\tkzDrawSegment[black!60!black](C,A)
\tkzDrawSegment[black!60!black](A,B)
\tkzDrawSegment[black!60!black](C,B)
\tkzDrawAltitude[color=black](A,B)(C)
\tkzGetPoint{D}%Get the point of intersection
\tkzLabelPoint[below](D){$D$}
\tkzMarkRightAngle(C,D,A)%Mark with a right angle symbol
\end{tikzpicture}
\end{center}
\end{multicols}
\end{document}


Edit: with minipage environment

\documentclass[12pt, letterpaper]{article}
\usepackage[
a4paper,top=1in,bottom=1in,left=0.7in,right=0.7in,headheight=14.5pt,]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[misc]{ifsym}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{forest}
\usepackage{tikz}
\usepackage{tkz-euclide}
\usetkzobj{all}
\begin{document}

\noindent\textbf{Solution: 5}

\noindent\begin{minipage}[t]{0.45\textwidth}
In $\triangle ABC,$ $CD\perp AB$ and $\angle D= 90^{\circ}$
Given that,
\begin{align*}
\cos A &=\cos B\\[6pt]
\therefore\;\;\dfrac{AD}{AC}&=\dfrac{BD}{BC}\\[6pt]
\therefore\;\;\dfrac{AD}{BD}&=\dfrac{AC}{BC}= k\quad (\text{say})\\[6pt]
\therefore\;\;AD&=kBD \tag{1}\\[6pt]
AC&=kBC \tag{2}
\end{align*}
\end{minipage}
\noindent\begin{minipage}[t]{0.45\textwidth}
\begin{center}
\begin{tikzpicture}[auto]
\tkzInit[xmin=-1,xmax=7,ymin=-1,ymax=4]\tkzClip
\tkzDefPoint(0:0){A}
\tkzDefPoint(0:6){B}
\tkzDefPoint(45:4){C}
\tkzLabelPoint[above](C){$C$}
\tkzLabelPoint[below,yshift=-0.8mm](B){$B$}
\tkzLabelPoint[below,yshift=-0.8mm](A){$A$}
\tkzDrawSegment[black!60!black](C,A)
\tkzDrawSegment[black!60!black](A,B)
\tkzDrawSegment[black!60!black](C,B)
\tkzDrawAltitude[color=black](A,B)(C)
\tkzGetPoint{D}%Get the point of intersection
\tkzLabelPoint[below](D){$D$}
\tkzMarkRightAngle(C,D,A)%Mark with a right angle symbol
\end{tikzpicture}
\end{center}
\end{minipage}
\end{document}

• you mentioned something like \tkzInit[xmin=-1,xmax=7,ymin=-1,ymax=4]\tkzClip how can i use in my codes Commented Mar 3, 2016 at 15:14
• After \begin{tikzpicture}[auto] as it is illustrated in my example. In fact, you just have to copy and paste my example to test if it satisfies your requirements. Commented Mar 3, 2016 at 15:30
• One more question, is the same output possible by mini page? If yes please tell me coz m very curious about it. Commented Mar 4, 2016 at 5:22
• I edit my answer to use minipage environment. If it works for you, please validate the answer. Commented Mar 4, 2016 at 7:14

As David mentioned, the quickest solution to these types of problems is by forcing the object to move upwards by adding \vspace{-3cm} or suchlike before it (negative vertical distance).

I think you may find the package parskip useful since you have used \noindent before each paragraph. \usepackage{parskip} takes away indentation and instead separates paragraphs with a small vertical space.

Secondly, you can shorten your code by calling a bunch of packages together:

\usepackage{amsmath, amsfonts, mathtools, amssymb, forest, tikz, tkz-euclide}


Naturally, those packages that you need to choose options for in the square brackets can't be bundled together with these others.