Caption alignment in tabularx

I want to take the caption of the table to right from left. Is it possible?

\documentclass[a4paper]{article}
\usepackage{enumitem}
\usepackage{array}
\usepackage{multirow}
\usepackage{ltablex, booktabs}
\renewcommand{\tabularxcolumn}[1]{>{\raggedright\arraybackslash}m{#1}}
\usepackage{arydshln}
\setlength\dashlinedash{0.2pt}
\setlength\dashlinegap{1pt}
\setlength\arrayrulewidth{0.3pt}
\usepackage[tableposition=below]{caption}
\newcommand{\myhdashline}{%
\hdashline
\usepackage{subfiles}
\usepackage{caption}
\usepackage{pdflscape}
\usepackage{rotating}
\usepackage{floatpag}
\usepackage{float}
\usepackage{titlesec}
\titleformat{\section}
{\normalfont\Large\bfseries}
{\thesection.}{0.5em}{}
\titleformat{\subsection}
{\normalfont\bfseries}
{\thesubsection.}{0.5em}{}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\begin{document}

\begin{tabularx}{\textwidth}
{>{\hsize=1.3\hsize}X>{\hsize=0.7\hsize}X}

\textbf{Caption} \\ \midrule \endhead \bottomrule \endfoot

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\textbf{Title} & \\hline

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

TextTextTextTextTextTextText&TextTextTextTextTextTextText\\myhdashline
TextTextTextTextTextTextText & TextTextTextTextTextTextText
\\myhdashline TextTextTextTextTextTextText &
TextTextTextTextTextTextText

\end{tabularx}

\end{document}

• You seem to be mixing longtable notation with your use of tabularx... – Werner Dec 28 '18 at 17:50
• caption had not to be inside tabularx environment. exception is when you use ltablex package, but this is not evident from your document example. – Zarko Dec 28 '18 at 17:50
• sorry I forget to add packages I used. Yes, I installed ltablex. – nebtune Dec 28 '18 at 17:58
• @nebtune, please edit your question and add missing packages and explain your problem better. is your table with tabularx environment really so long that had to be broken over two or more pages? – Zarko Dec 28 '18 at 18:01
• @ Zarko I tried to add what you suggested. I hope it works. Sorry, I am not so familiar with these. – nebtune Dec 28 '18 at 18:39

You are manually placing the caption within your tabular. If you want it to a) span the whole width and b) be right aligned, you could use a \multicolumn. Alternatively you could simply place a real caption outside the tabular.

\documentclass[a4paper]{article}

\usepackage{array}
\usepackage{multirow}
\usepackage{ltablex, booktabs}
\renewcommand{\tabularxcolumn}[1]{>{\raggedright\arraybackslash}m{#1}}

\begin{document}

\begin{tabularx}{\textwidth}
{>{\hsize=1.3\hsize}X>{\hsize=0.7\hsize}X}

\textbf{Caption} \\ \midrule \endhead \bottomrule \endfoot

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\textbf{Title} & \\hline

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

TextTextTextTextTextTextText&TextTextTextTextTextTextText\\myhdashline
TextTextTextTextTextTextText & TextTextTextTextTextTextText
\\myhdashline TextTextTextTextTextTextText &
TextTextTextTextTextTextText

\end{tabularx}

\end{document}